Skip to content

Commit

Permalink
Merge pull request ziglang#7431 from LemonBoy/fix-7426
Browse files Browse the repository at this point in the history
stage1: Fix crash in can_mutate_comptime_var_state
  • Loading branch information
andrewrk committed Dec 15, 2020
2 parents b3f4802 + bbfa355 commit b3c1ced
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/stage1/analyze.cpp
Expand Up @@ -5729,6 +5729,28 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {
assert(value != nullptr);
if (value->special == ConstValSpecialUndef)
return false;

if (value->special == ConstValSpecialLazy) {
// No lazy value has side effects.
// Use a switch here to get a compile error whenever a new kind of lazy
// value is added.
switch (value->data.x_lazy->id) {
case LazyValueIdInvalid:
zig_unreachable();

case LazyValueIdAlignOf:
case LazyValueIdSizeOf:
case LazyValueIdPtrType:
case LazyValueIdOptType:
case LazyValueIdSliceType:
case LazyValueIdFnType:
case LazyValueIdErrUnionType:
case LazyValueIdArrayType:
case LazyValueIdTypeInfoDecls:
return false;
}
}

switch (value->type->id) {
case ZigTypeIdInvalid:
zig_unreachable();
Expand Down
7 changes: 7 additions & 0 deletions test/stage1/behavior/misc.zig
Expand Up @@ -752,3 +752,10 @@ test "extern variable with non-pointer opaque type" {
@export(var_to_export, .{ .name = "opaque_extern_var" });
expect(@ptrCast(*align(1) u32, &opaque_extern_var).* == 42);
}

test "lazy typeInfo value as generic parameter" {
const S = struct {
fn foo(args: anytype) void {}
};
S.foo(@typeInfo(@TypeOf(.{})));
}

0 comments on commit b3c1ced

Please sign in to comment.