authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-12-08 10:37:53+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-08 10:28:29-05:00
log19c1b5a33a21bdddfbbca3c65b1c0e6419c4629f
treef91d9c382ccc40d80ba0904bdaf4ff20cdc5d705
parent05fc4d34a93d1e8fd4a107cb17c9d4fd7ffc29bc

Fix for @Type not picking up the sentinel value

The code converted the whole TypeInfo payload into an optional type instead of using the "sentinel" field value. Fixes #3828

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

src/ir.cpp+1-1
......@@ -23065,7 +23065,7 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
2306523065 if (field_val == nullptr)
2306623066 return ErrorSemanticAnalyzeFail;
2306723067
23068 IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
23068 IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val);
2306923069 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
2307023070 get_optional_type(ira->codegen, elem_type));
2307123071 if (type_is_invalid(casted_field_inst->value->type))
test/stage1/behavior/type.zig+27
......@@ -144,3 +144,30 @@ test "@Type create slice with null sentinel" {
144144 });
145145 testing.expect(Slice == []align(8) const *i32);
146146}
147test "@Type picks up the sentinel value from TypeInfo" {
148 testTypes(&[_]type{
149 [11:0]u8, [4:10]u8,
150 [*:0]u8, [*:0]const u8,
151 [*:0]volatile u8, [*:0]const volatile u8,
152 [*:0]align(4) u8, [*:0]align(4) const u8,
153 [*:0]align(4) volatile u8, [*:0]align(4) const volatile u8,
154 [*:0]align(8) u8, [*:0]align(8) const u8,
155 [*:0]align(8) volatile u8, [*:0]align(8) const volatile u8,
156 [*:0]allowzero u8, [*:0]allowzero const u8,
157 [*:0]allowzero volatile u8, [*:0]allowzero const volatile u8,
158 [*:0]allowzero align(4) u8, [*:0]allowzero align(4) const u8,
159 [*:0]allowzero align(4) volatile u8, [*:0]allowzero align(4) const volatile u8,
160 [*:5]allowzero align(4) volatile u8, [*:5]allowzero align(4) const volatile u8,
161 [:0]u8, [:0]const u8,
162 [:0]volatile u8, [:0]const volatile u8,
163 [:0]align(4) u8, [:0]align(4) const u8,
164 [:0]align(4) volatile u8, [:0]align(4) const volatile u8,
165 [:0]align(8) u8, [:0]align(8) const u8,
166 [:0]align(8) volatile u8, [:0]align(8) const volatile u8,
167 [:0]allowzero u8, [:0]allowzero const u8,
168 [:0]allowzero volatile u8, [:0]allowzero const volatile u8,
169 [:0]allowzero align(4) u8, [:0]allowzero align(4) const u8,
170 [:0]allowzero align(4) volatile u8, [:0]allowzero align(4) const volatile u8,
171 [:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8,
172 });
173}