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) {...@@ -2804,7 +2804,6 @@ static bool is_container(TypeTableEntry *type_entry) {
2804 switch (type_entry->id) {2804 switch (type_entry->id) {
2805 case TypeTableEntryIdInvalid:2805 case TypeTableEntryIdInvalid:
2806 case TypeTableEntryIdVar:2806 case TypeTableEntryIdVar:
2807 case TypeTableEntryIdOpaque:
2808 zig_unreachable();2807 zig_unreachable();
2809 case TypeTableEntryIdStruct:2808 case TypeTableEntryIdStruct:
2810 case TypeTableEntryIdEnum:2809 case TypeTableEntryIdEnum:
...@@ -2831,6 +2830,7 @@ static bool is_container(TypeTableEntry *type_entry) {...@@ -2831,6 +2830,7 @@ static bool is_container(TypeTableEntry *type_entry) {
2831 case TypeTableEntryIdBoundFn:2830 case TypeTableEntryIdBoundFn:
2832 case TypeTableEntryIdEnumTag:2831 case TypeTableEntryIdEnumTag:
2833 case TypeTableEntryIdArgTuple:2832 case TypeTableEntryIdArgTuple:
2833 case TypeTableEntryIdOpaque:
2834 return false;2834 return false;
2835 }2835 }
2836 zig_unreachable();2836 zig_unreachable();
test/compile_errors.zig+14
...@@ -2238,4 +2238,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2238,4 +2238,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2238 \\}2238 \\}
2239 ,2239 ,
2240 ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable");2240 ".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");
2241}2255}