authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-07 14:23:06-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-04-07 14:23:06-07:00
log3b535d2c3af5259a71916681d87ab0c01f24b58d
tree61816becd81c72f3a8af790798c0f42bf443b5d9
parentee22e872967947d2f6e64cba888bf7bf56e4d332

fix evaluating generic function instance in wrong context

See #22

2 files changed, 8 insertions(+), 1 deletions(-)

src/analyze.cpp+1-1
...@@ -4674,7 +4674,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp...@@ -4674,7 +4674,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
4674 }4674 }
4675 AstNode **param_node = &node->data.fn_call_expr.params.at(i);4675 AstNode **param_node = &node->data.fn_call_expr.params.at(i);
46764676
4677 TypeTableEntry *param_type = analyze_expression(g, import, child_context, expected_param_type,4677 TypeTableEntry *param_type = analyze_expression(g, import, parent_context, expected_param_type,
4678 *param_node);4678 *param_node);
4679 if (param_type->id == TypeTableEntryIdInvalid) {4679 if (param_type->id == TypeTableEntryIdInvalid) {
4680 return param_type;4680 return param_type;
test/run_tests.cpp+7
...@@ -1781,6 +1781,13 @@ b";...@@ -1781,6 +1781,13 @@ b";
1781fn foo() {}1781fn foo() {}
1782const invalid = foo > foo;1782const invalid = foo > foo;
1783 )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'");1783 )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'");
1784
1785 add_compile_fail_case("generic function instance with non-constant expression", R"SOURCE(
1786fn foo(x: i32)(y: i32) -> i32 { return x + y; }
1787fn test1(a: i32, b: i32) -> i32 {
1788 return foo(a)(b);
1789}
1790 )SOURCE", 1, ".tmp_source.zig:4:16: error: unable to resolve constant expression");
1784}1791}
17851792
1786//////////////////////////////////////////////////////////////////////////////1793//////////////////////////////////////////////////////////////////////////////