authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-17 23:00:01+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-20 20:25:12+02:00
log98b3734b67739ad0e7d53500308495d53250cab0
treeebc912c09bec23cf429c52ecb7c170d21f0e76e8
parent9877a7d36c466a25fe722aa3ff301ee90b206d9c

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

Closes #12275

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

src/Sema.zig+6-1
......@@ -1897,10 +1897,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
18971897 }
18981898 i -= Air.Inst.Ref.typed_value_map.len;
18991899
1900 const air_tags = sema.air_instructions.items(.tag);
19001901 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
1902 if (air_tags[i] == .constant) {
1903 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
1904 const val = sema.air_values.items[ty_pl.payload];
1905 if (val.tag() == .variable) return val;
1906 }
19011907 return opv;
19021908 }
1903 const air_tags = sema.air_instructions.items(.tag);
19041909 switch (air_tags[i]) {
19051910 .constant => {
19061911 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
test/behavior/basic.zig+9
......@@ -1118,3 +1118,12 @@ test "ambiguous reference error ignores current declaration" {
11181118 };
11191119 try expect(S.b.foo == 666);
11201120}
1121
1122test "pointer to zero sized global is mutable" {
1123 const S = struct {
1124 const Thing = struct {};
1125
1126 var thing: Thing = undefined;
1127 };
1128 try expect(@TypeOf(&S.thing) == *S.Thing);
1129}