authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-25 23:18:18-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-25 23:18:18-04:00
log300c83d8930d15d4bc4e34fe11e3b6bf3130ecc4
tree265aaeaaddef394074b425c0798bf656a8b09cb9
parent5f28a9d23851d94edc2b24e549b7c5abbbf23f68

fix crash on field access of opaque type


2 files changed, 15 insertions(+), 1 deletions(-)

src/analyze.cpp+1-1
......@@ -2804,7 +2804,6 @@ static bool is_container(TypeTableEntry *type_entry) {
28042804 switch (type_entry->id) {
28052805 case TypeTableEntryIdInvalid:
28062806 case TypeTableEntryIdVar:
2807 case TypeTableEntryIdOpaque:
28082807 zig_unreachable();
28092808 case TypeTableEntryIdStruct:
28102809 case TypeTableEntryIdEnum:
......@@ -2831,6 +2830,7 @@ static bool is_container(TypeTableEntry *type_entry) {
28312830 case TypeTableEntryIdBoundFn:
28322831 case TypeTableEntryIdEnumTag:
28332832 case TypeTableEntryIdArgTuple:
2833 case TypeTableEntryIdOpaque:
28342834 return false;
28352835 }
28362836 zig_unreachable();
test/compile_errors.zig+14
......@@ -2238,4 +2238,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
22382238 \\}
22392239 ,
22402240 ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable");
2241
2242 cases.add("field access of opaque type",
2243 \\const MyType = @OpaqueType();
2244 \\
2245 \\export fn entry() -> bool {
2246 \\ var x: i32 = 1;
2247 \\ return bar(@ptrCast(&MyType, &x));
2248 \\}
2249 \\
2250 \\fn bar(x: &MyType) -> bool {
2251 \\ return x.blah;
2252 \\}
2253 ,
2254 ".tmp_source.zig:9:13: error: type '&MyType' does not support field access");
22412255}