authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-15 15:07:49-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-12-15 15:07:49-05:00
logb3c1ced2c37a8265314833fd74a105ca788db927
tree49c7b8ef8bcd8325bf11ab427f0ef9c91fcaa5fd
parentb3f4802aa0436346d423db5a3f04fdd804b1d364
parentbbfa3550a02e82df91f5e2fafeab564906ae943c
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7431 from LemonBoy/fix-7426

stage1: Fix crash in can_mutate_comptime_var_state

2 files changed, 29 insertions(+), 0 deletions(-)

src/stage1/analyze.cpp+22
......@@ -5729,6 +5729,28 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {
57295729 assert(value != nullptr);
57305730 if (value->special == ConstValSpecialUndef)
57315731 return false;
5732
5733 if (value->special == ConstValSpecialLazy) {
5734 // No lazy value has side effects.
5735 // Use a switch here to get a compile error whenever a new kind of lazy
5736 // value is added.
5737 switch (value->data.x_lazy->id) {
5738 case LazyValueIdInvalid:
5739 zig_unreachable();
5740
5741 case LazyValueIdAlignOf:
5742 case LazyValueIdSizeOf:
5743 case LazyValueIdPtrType:
5744 case LazyValueIdOptType:
5745 case LazyValueIdSliceType:
5746 case LazyValueIdFnType:
5747 case LazyValueIdErrUnionType:
5748 case LazyValueIdArrayType:
5749 case LazyValueIdTypeInfoDecls:
5750 return false;
5751 }
5752 }
5753
57325754 switch (value->type->id) {
57335755 case ZigTypeIdInvalid:
57345756 zig_unreachable();
test/stage1/behavior/misc.zig+7
......@@ -752,3 +752,10 @@ test "extern variable with non-pointer opaque type" {
752752 @export(var_to_export, .{ .name = "opaque_extern_var" });
753753 expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);
754754}
755
756test "lazy typeInfo value as generic parameter" {
757 const S = struct {
758 fn foo(args: anytype) void {}
759 };
760 S.foo(@typeInfo(@TypeOf(.{})));
761}