diff --git a/src/analyze.cpp b/src/analyze.cpp index 879de7ab92..cb651995e2 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1333,7 +1333,7 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa if (implicit_type->id == TypeTableEntryIdMaybe) { implicit_type = implicit_type->data.maybe.child_type; } else { - add_node_error(g, source_node, buf_sprintf("expected maybe type")); + add_node_error(g, variable_declaration->expr, buf_sprintf("expected maybe type")); implicit_type = g->builtin_types.entry_invalid; } } else if (implicit_type->id == TypeTableEntryIdUnreachable) { diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 5c3e5f5257..973c158705 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -982,6 +982,12 @@ fn f() { continue; } )SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression not in loop"); + + add_compile_fail_case("invalid maybe type", R"SOURCE( +fn f() { + if (const x ?= true) { } +} + )SOURCE", 1, ".tmp_source.zig:3:20: error: expected maybe type"); } static void print_compiler_invocation(TestCase *test_case) {