Commit 300c83d893

Andrew Kelley <superjoe30@gmail.com>
2017-10-26 05:18:18
fix crash on field access of opaque type
1 parent 5f28a9d
Changed files (2)
src/analyze.cpp
@@ -2804,7 +2804,6 @@ static bool is_container(TypeTableEntry *type_entry) {
     switch (type_entry->id) {
         case TypeTableEntryIdInvalid:
         case TypeTableEntryIdVar:
-        case TypeTableEntryIdOpaque:
             zig_unreachable();
         case TypeTableEntryIdStruct:
         case TypeTableEntryIdEnum:
@@ -2831,6 +2830,7 @@ static bool is_container(TypeTableEntry *type_entry) {
         case TypeTableEntryIdBoundFn:
         case TypeTableEntryIdEnumTag:
         case TypeTableEntryIdArgTuple:
+        case TypeTableEntryIdOpaque:
             return false;
     }
     zig_unreachable();
test/compile_errors.zig
@@ -2238,4 +2238,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
         \\}
     ,
         ".tmp_source.zig:37:16: error: cannot store runtime value in compile time variable");
+
+    cases.add("field access of opaque type",
+        \\const MyType = @OpaqueType();
+        \\
+        \\export fn entry() -> bool {
+        \\    var x: i32 = 1;
+        \\    return bar(@ptrCast(&MyType, &x));
+        \\}
+        \\
+        \\fn bar(x: &MyType) -> bool {
+        \\    return x.blah;
+        \\}
+    ,
+        ".tmp_source.zig:9:13: error: type '&MyType' does not support field access");
 }