Commit 7c99c30bf4

Andrew Kelley <superjoe30@gmail.com>
2018-06-20 01:35:35
fix calling method with comptime pass-by-non-copyign-value self arg
closes #1124
1 parent 42db807
Changed files (2)
src
test
cases
src/analyze.cpp
@@ -1470,6 +1470,17 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
                             calling_convention_name(fn_type_id.cc)));
                 return g->builtin_types.entry_invalid;
             }
+            if (param_node->data.param_decl.type != nullptr) {
+                TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type);
+                if (type_is_invalid(type_entry)) {
+                    return g->builtin_types.entry_invalid;
+                }
+                FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];
+                param_info->type = type_entry;
+                param_info->is_noalias = param_node->data.param_decl.is_noalias;
+                fn_type_id.next_param_index += 1;
+            }
+
             return get_generic_fn_type(g, &fn_type_id);
         } else if (param_is_var_args) {
             if (fn_type_id.cc == CallingConventionC) {
test/cases/eval.zig
@@ -623,3 +623,17 @@ test "function which returns struct with type field causes implicit comptime" {
     const ty = wrap(i32).T;
     assert(ty == i32);
 }
+
+test "call method with comptime pass-by-non-copying-value self parameter" {
+    const S = struct {
+        a: u8,
+
+        fn b(comptime s: this) u8 {
+            return s.a;
+        }
+    };
+
+    const s = S{ .a = 2 };
+    var b = s.b();
+    assert(b == 2);
+}