From 3b535d2c3af5259a71916681d87ab0c01f24b58d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 7 Apr 2016 14:23:06 -0700 Subject: [PATCH] fix evaluating generic function instance in wrong context See #22 --- src/analyze.cpp | 2 +- test/run_tests.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 75002ebb66..b1ffa8b969 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4674,7 +4674,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp } AstNode **param_node = &node->data.fn_call_expr.params.at(i); - TypeTableEntry *param_type = analyze_expression(g, import, child_context, expected_param_type, + TypeTableEntry *param_type = analyze_expression(g, import, parent_context, expected_param_type, *param_node); if (param_type->id == TypeTableEntryIdInvalid) { return param_type; diff --git a/test/run_tests.cpp b/test/run_tests.cpp index fb232aed70..0ff7385d94 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1781,6 +1781,13 @@ b"; fn foo() {} const invalid = foo > foo; )SOURCE", 1, ".tmp_source.zig:3:21: error: operator not allowed for type 'fn()'"); + + add_compile_fail_case("generic function instance with non-constant expression", R"SOURCE( +fn foo(x: i32)(y: i32) -> i32 { return x + y; } +fn test1(a: i32, b: i32) -> i32 { + return foo(a)(b); +} + )SOURCE", 1, ".tmp_source.zig:4:16: error: unable to resolve constant expression"); } //////////////////////////////////////////////////////////////////////////////