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(...@@ -1897,10 +1897,15 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
1897 }1897 }
1898 i -= Air.Inst.Ref.typed_value_map.len;1898 i -= Air.Inst.Ref.typed_value_map.len;
18991899
1900 const air_tags = sema.air_instructions.items(.tag);
1900 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {1901 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 }
1901 return opv;1907 return opv;
1902 }1908 }
1903 const air_tags = sema.air_instructions.items(.tag);
1904 switch (air_tags[i]) {1909 switch (air_tags[i]) {
1905 .constant => {1910 .constant => {
1906 const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;1911 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" {...@@ -1118,3 +1118,12 @@ test "ambiguous reference error ignores current declaration" {
1118 };1118 };
1119 try expect(S.b.foo == 666);1119 try expect(S.b.foo == 666);
1120}1120}
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}