From 7c99c30bf406342a45833963ce630bb104aef00e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 Jun 2018 19:35:35 -0400 Subject: [PATCH] fix calling method with comptime pass-by-non-copyign-value self arg closes #1124 --- src/analyze.cpp | 11 +++++++++++ test/cases/eval.zig | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/analyze.cpp b/src/analyze.cpp index 10cdb0af6f..479abef16a 100644 --- a/src/analyze.cpp +++ b/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) { diff --git a/test/cases/eval.zig b/test/cases/eval.zig index 6c919e17a6..756ffe339a 100644 --- a/test/cases/eval.zig +++ b/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); +}