disable field access for unknown length pointers

See #770
This commit is contained in:
Andrew Kelley 2018-06-05 20:24:11 -04:00
parent bbb565a21e
commit 0ccc186869
2 changed files with 15 additions and 2 deletions

View File

@ -3753,13 +3753,13 @@ static bool is_container(TypeTableEntry *type_entry) {
}
bool is_container_ref(TypeTableEntry *type_entry) {
return (type_entry->id == TypeTableEntryIdPointer) ?
return (type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle) ?
is_container(type_entry->data.pointer.child_type) : is_container(type_entry);
}
TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) {
assert(is_container_ref(type_entry));
return (type_entry->id == TypeTableEntryIdPointer) ?
return (type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle) ?
type_entry->data.pointer.child_type : type_entry;
}

View File

@ -1,6 +1,19 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"field access of unknown length pointer",
\\const Foo = extern struct {
\\ a: i32,
\\};
\\
\\export fn entry(foo: [*]Foo) void {
\\ foo.a += 1;
\\}
,
".tmp_source.zig:6:8: error: type '[*]Foo' does not support field access",
);
cases.add(
"unknown length pointer to opaque",
\\export const T = [*]@OpaqueType();