mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Sema: prioritize Value.variable over OPV when resolving const value
Closes #12275
This commit is contained in:
parent
9877a7d36c
commit
98b3734b67
@ -1897,10 +1897,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
|
||||
}
|
||||
i -= Air.Inst.Ref.typed_value_map.len;
|
||||
|
||||
const air_tags = sema.air_instructions.items(.tag);
|
||||
if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
|
||||
if (air_tags[i] == .constant) {
|
||||
const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
|
||||
const val = sema.air_values.items[ty_pl.payload];
|
||||
if (val.tag() == .variable) return val;
|
||||
}
|
||||
return opv;
|
||||
}
|
||||
const air_tags = sema.air_instructions.items(.tag);
|
||||
switch (air_tags[i]) {
|
||||
.constant => {
|
||||
const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
|
||||
|
||||
@ -1118,3 +1118,12 @@ test "ambiguous reference error ignores current declaration" {
|
||||
};
|
||||
try expect(S.b.foo == 666);
|
||||
}
|
||||
|
||||
test "pointer to zero sized global is mutable" {
|
||||
const S = struct {
|
||||
const Thing = struct {};
|
||||
|
||||
var thing: Thing = undefined;
|
||||
};
|
||||
try expect(@TypeOf(&S.thing) == *S.Thing);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user