diff --git a/src/analyze.cpp b/src/analyze.cpp index bae41742b4..5bcd7cc0ba 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2468,6 +2468,10 @@ static TypeTableEntry *analyze_enum_value_expr(CodeGen *g, ImportTableEntry *imp assert(field_access_node->type == NodeTypeFieldAccessExpr); TypeEnumField *type_enum_field = get_enum_field(enum_type, field_name); + if (type_enum_field->type_entry->id == TypeTableEntryIdInvalid) { + return g->builtin_types.entry_invalid; + } + field_access_node->data.field_access_expr.type_enum_field = type_enum_field; if (type_enum_field) { diff --git a/test/run_tests.cpp b/test/run_tests.cpp index bbf1fd2168..4f86519879 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -1501,6 +1501,39 @@ fn foo(blah: []u8) { for (blah) { } } )SOURCE", 1, ".tmp_source.zig:3:16: error: for loop expression missing element parameter"); + + add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE( +const JasonHM = u8; +const JasonList = &JsonNode; + +enum JsonOA { + JSONArray: JsonList, + JSONObject: JasonHM, +} + +enum JsonType { + JSONNull: void, + JSONInteger: isize, + JSONDouble: f64, + JSONBool: bool, + JSONString: []u8, + JSONArray, + JSONObject, +} + +pub struct JsonNode { + kind: JsonType, + jobject: ?JsonOA, +} + +fn foo() { + var jll: JasonList = undefined; + jll.init(&debug.global_allocator); + var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} }; +} + )SOURCE", 2, + ".tmp_source.zig:6:16: error: use of undeclared identifier 'JsonList'", + ".tmp_source.zig:27:8: error: no function named 'init' in 'JsonNode'"); } //////////////////////////////////////////////////////////////////////////////