authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-23 11:53:05-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-09-23 11:53:05-04:00
log9ec6a78f121c8f61c10ea02f6949f27b0228ba16
treee08bf750cfd8181fff72d52d20139e6cd6a805b7
parent46eb77dbb200756b96bfae4c5166397fefba66d0

fix compiler crash for misspelled type with pointer only reference

closes #196

2 files changed, 37 insertions(+), 0 deletions(-)

src/analyze.cpp+4
......@@ -2468,6 +2468,10 @@ static TypeTableEntry *analyze_enum_value_expr(CodeGen *g, ImportTableEntry *imp
24682468 assert(field_access_node->type == NodeTypeFieldAccessExpr);
24692469
24702470 TypeEnumField *type_enum_field = get_enum_field(enum_type, field_name);
2471 if (type_enum_field->type_entry->id == TypeTableEntryIdInvalid) {
2472 return g->builtin_types.entry_invalid;
2473 }
2474
24712475 field_access_node->data.field_access_expr.type_enum_field = type_enum_field;
24722476
24732477 if (type_enum_field) {
test/run_tests.cpp+33
......@@ -1501,6 +1501,39 @@ fn foo(blah: []u8) {
15011501 for (blah) { }
15021502}
15031503 )SOURCE", 1, ".tmp_source.zig:3:16: error: for loop expression missing element parameter");
1504
1505 add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE(
1506const JasonHM = u8;
1507const JasonList = &JsonNode;
1508
1509enum JsonOA {
1510 JSONArray: JsonList,
1511 JSONObject: JasonHM,
1512}
1513
1514enum JsonType {
1515 JSONNull: void,
1516 JSONInteger: isize,
1517 JSONDouble: f64,
1518 JSONBool: bool,
1519 JSONString: []u8,
1520 JSONArray,
1521 JSONObject,
1522}
1523
1524pub struct JsonNode {
1525 kind: JsonType,
1526 jobject: ?JsonOA,
1527}
1528
1529fn foo() {
1530 var jll: JasonList = undefined;
1531 jll.init(&debug.global_allocator);
1532 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
1533}
1534 )SOURCE", 2,
1535 ".tmp_source.zig:6:16: error: use of undeclared identifier 'JsonList'",
1536 ".tmp_source.zig:27:8: error: no function named 'init' in 'JsonNode'");
15041537}
15051538
15061539//////////////////////////////////////////////////////////////////////////////