error for if var expression not maybe type

master
Andrew Kelley 2016-01-02 00:09:49 -07:00
parent 9a8851515b
commit 724dcdd384
2 changed files with 7 additions and 1 deletions

View File

@ -1333,7 +1333,7 @@ static VariableTableEntry *analyze_variable_declaration_raw(CodeGen *g, ImportTa
if (implicit_type->id == TypeTableEntryIdMaybe) { if (implicit_type->id == TypeTableEntryIdMaybe) {
implicit_type = implicit_type->data.maybe.child_type; implicit_type = implicit_type->data.maybe.child_type;
} else { } 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; implicit_type = g->builtin_types.entry_invalid;
} }
} else if (implicit_type->id == TypeTableEntryIdUnreachable) { } else if (implicit_type->id == TypeTableEntryIdUnreachable) {

View File

@ -982,6 +982,12 @@ fn f() {
continue; continue;
} }
)SOURCE", 1, ".tmp_source.zig:3:5: error: 'continue' expression not in loop"); )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) { static void print_compiler_invocation(TestCase *test_case) {