Commit 724dcdd384

Andrew Kelley <superjoe30@gmail.com>
2016-01-02 08:09:49
error for if var expression not maybe type
1 parent 9a88515
Changed files (2)
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) {
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) {