zig/test/behavior/bugs/12486.zig
martinhath 3fa5415253
Sema: ensure resolveTypeFields is called for optional and error union types
We call `sema.resolveTypeFields` in order to get the fields of structs
and unions inserted into their data structures. If it isn't called, it
can happen that the fields of a type is queried before those fields are
inserted into (for instance) `Module.Union.fields`, which would result in
a wrong 'no field named' error.

Fixes: #12486
2022-08-26 11:37:17 +03:00

50 lines
728 B
Zig

const SomeEnum = union(enum) {
EnumVariant: u8,
};
const SomeStruct = struct {
struct_field: u8,
};
const OptEnum = struct {
opt_enum: ?SomeEnum,
};
const ErrEnum = struct {
err_enum: anyerror!SomeEnum,
};
const OptStruct = struct {
opt_struct: ?SomeStruct,
};
const ErrStruct = struct {
err_struct: anyerror!SomeStruct,
};
test {
_ = OptEnum{
.opt_enum = .{
.EnumVariant = 1,
},
};
_ = ErrEnum{
.err_enum = .{
.EnumVariant = 1,
},
};
_ = OptStruct{
.opt_struct = .{
.struct_field = 1,
},
};
_ = ErrStruct{
.err_struct = .{
.struct_field = 1,
},
};
}