diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-10 16:08:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-10 17:52:18 -0700 |
| commit | a30d283981ae31ed0212ef153f086e07daeffe65 (patch) | |
| tree | 88be9a44382b0a79f42a74a3bb43781e6365fea7 /src/AstGen.zig | |
| parent | b642fa24a67f88082b768d39e443b03c7446be76 (diff) | |
| download | zig-a30d283981ae31ed0212ef153f086e07daeffe65.tar.gz zig-a30d283981ae31ed0212ef153f086e07daeffe65.zip | |
AstGen: lower anon struct inits differently
This is a companion commit to f2a5d0bf94897554e25e889dc1c6c4c7fc6c1217.
What that one did for tuples, this one does for anonymous structs.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index e39c7abffe..eb724934c9 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -1352,6 +1352,7 @@ fn arrayInitExpr( if (types.array == .none) { // We treat this case differently so that we don't get a crash when // analyzing array_base_ptr against an alloc_inferred_mut. + // See corresponding logic in structInitExpr. const result = try arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon); return rvalue(gz, rl, result, node); } else { @@ -1591,7 +1592,18 @@ fn structInitExpr( const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init); return rvalue(gz, rl, result, node); }, - .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst), + .ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst), + .inferred_ptr => |ptr_inst| { + if (struct_init.ast.type_expr == 0) { + // We treat this case differently so that we don't get a crash when + // analyzing field_base_ptr against an alloc_inferred_mut. + // See corresponding logic in arrayInitExpr. + const result = try structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon); + return rvalue(gz, rl, result, node); + } else { + return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst); + } + }, .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr), } } |
