diff options
| author | Mason Remaley <mason@anthropicstudios.com> | 2025-02-15 15:42:59 -0800 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-04-02 05:53:22 +0100 |
| commit | 06ee383da9a23016dcb25ff7cb6811e3dc2c387e (patch) | |
| tree | a1f407023746af27e8338c08b34a57336ae50cc6 /src/Sema.zig | |
| parent | 1b62a22268117340ee7a17f019df01cd39ec1421 (diff) | |
| download | zig-06ee383da9a23016dcb25ff7cb6811e3dc2c387e.tar.gz zig-06ee383da9a23016dcb25ff7cb6811e3dc2c387e.zip | |
compiler: allow `@import` of ZON without a result type
In particular, this allows importing `build.zig.zon` at comptime.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 54be47f584..40c170cbe7 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2998,7 +2998,7 @@ fn zirStructDecl( return Air.internedToRef(wip_ty.finish(ip, new_namespace_index)); } -fn createTypeName( +pub fn createTypeName( sema: *Sema, block: *Block, name_strategy: Zir.Inst.NameStrategy, @@ -14065,14 +14065,13 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. return Air.internedToRef(ty); }, .zon => { - if (extra.res_ty == .none) { - return sema.fail(block, operand_src, "'@import' of ZON must have a known result type", .{}); - } - const res_ty_inst = try sema.resolveInst(extra.res_ty); - const res_ty = try sema.analyzeAsType(block, operand_src, res_ty_inst); - if (res_ty.isGenericPoison()) { - return sema.fail(block, operand_src, "'@import' of ZON must have a known result type", .{}); - } + const res_ty: InternPool.Index = b: { + if (extra.res_ty == .none) break :b .none; + const res_ty_inst = try sema.resolveInst(extra.res_ty); + const res_ty = try sema.analyzeAsType(block, operand_src, res_ty_inst); + if (res_ty.isGenericPoison()) break :b .none; + break :b res_ty.toIntern(); + }; try sema.declareDependency(.{ .zon_file = result.file_index }); const interned = try LowerZon.run( @@ -31699,7 +31698,7 @@ fn addReferenceEntry( try zcu.addUnitReference(sema.owner, referenced_unit, src); } -fn addTypeReferenceEntry( +pub fn addTypeReferenceEntry( sema: *Sema, src: LazySrcLoc, referenced_type: InternPool.Index, |
