Skip to content

Fix for @Type not picking up the sentinel value #3865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
27 changes: 27 additions & 0 deletions test/stage1/behavior/type.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}