Sema: prioritize Value.variable over OPV when resolving const value

Closes #12275
This commit is contained in:
Veikka Tuominen 2022-11-17 23:00:01 +02:00
parent 9877a7d36c
commit 98b3734b67
2 changed files with 15 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}