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
This commit is contained in:
LemonBoy 2019-12-08 10:37:53 +01:00 committed by Andrew Kelley
parent 05fc4d34a9
commit 19c1b5a33a
2 changed files with 28 additions and 1 deletions

View File

@ -23065,7 +23065,7 @@ static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_inst
if (field_val == nullptr)
return ErrorSemanticAnalyzeFail;
IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type);
IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val);
IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,
get_optional_type(ira->codegen, elem_type));
if (type_is_invalid(casted_field_inst->value->type))

View File

@ -144,3 +144,30 @@ test "@Type create slice with null sentinel" {
});
testing.expect(Slice == []align(8) const *i32);
}
test "@Type picks up the sentinel value from TypeInfo" {
testTypes(&[_]type{
[11:0]u8, [4:10]u8,
[*:0]u8, [*:0]const u8,
[*:0]volatile u8, [*:0]const volatile u8,
[*:0]align(4) u8, [*:0]align(4) const u8,
[*:0]align(4) volatile u8, [*:0]align(4) const volatile u8,
[*:0]align(8) u8, [*:0]align(8) const u8,
[*:0]align(8) volatile u8, [*:0]align(8) const volatile u8,
[*:0]allowzero u8, [*:0]allowzero const u8,
[*:0]allowzero volatile u8, [*:0]allowzero const volatile u8,
[*:0]allowzero align(4) u8, [*:0]allowzero align(4) const u8,
[*:0]allowzero align(4) volatile u8, [*:0]allowzero align(4) const volatile u8,
[*:5]allowzero align(4) volatile u8, [*:5]allowzero align(4) const volatile u8,
[:0]u8, [:0]const u8,
[:0]volatile u8, [:0]const volatile u8,
[:0]align(4) u8, [:0]align(4) const u8,
[:0]align(4) volatile u8, [:0]align(4) const volatile u8,
[:0]align(8) u8, [:0]align(8) const u8,
[:0]align(8) volatile u8, [:0]align(8) const volatile u8,
[:0]allowzero u8, [:0]allowzero const u8,
[:0]allowzero volatile u8, [:0]allowzero const volatile u8,
[:0]allowzero align(4) u8, [:0]allowzero align(4) const u8,
[:0]allowzero align(4) volatile u8, [:0]allowzero align(4) const volatile u8,
[:4]allowzero align(4) volatile u8, [:4]allowzero align(4) const volatile u8,
});
}