From 724dcdd384c6c00b9e39ed67867d364287e45f0a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 2 Jan 2016 00:09:49 -0700 Subject: [PATCH] error for if var expression not maybe type --- src/analyze.cpp | 2 +- test/run_tests.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 879de7ab9..cb651995e 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 5c3e5f525..973c15870 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) {