| author | |
| committer | |
| log | adc2aed587d009c0d112063fa0f3d03dedc9e50a |
| tree | 0e32f88c8729eadc2708af7e9d53f8517222cf96 |
| parent | 333a577d73cdbac420d25167a3955956af91b2eb |
See #22063 files changed, 16 insertions(+), 8 deletions(-)
src/AstGen.zig+11-2| ... | ... | @@ -4674,8 +4674,17 @@ fn builtinCall( |
| 4674 | 4674 | return rvalue(gz, scope, rl, .void_value, node); |
| 4675 | 4675 | }, |
| 4676 | 4676 | .import => { |
| 4677 | const target = try expr(gz, scope, .none, params[0]); | |
| 4678 | const result = try gz.addUnNode(.import, target, node); | |
| 4677 | const node_tags = tree.nodes.items(.tag); | |
| 4678 | const node_datas = tree.nodes.items(.data); | |
| 4679 | const operand_node = params[0]; | |
| 4680 | ||
| 4681 | if (node_tags[operand_node] != .string_literal) { | |
| 4682 | // Spec reference: https://github.com/ziglang/zig/issues/2206 | |
| 4683 | return astgen.failNode(operand_node, "@import operand must be a string literal", .{}); | |
| 4684 | } | |
| 4685 | const str_lit_token = main_tokens[operand_node]; | |
| 4686 | const str = try gz.strLitAsString(str_lit_token); | |
| 4687 | const result = try gz.addStrTok(.import, str.index, str_lit_token); | |
| 4679 | 4688 | return rvalue(gz, scope, rl, result, node); |
| 4680 | 4689 | }, |
| 4681 | 4690 | .error_to_int => { |
src/Sema.zig+2-3| ... | ... | @@ -3900,10 +3900,9 @@ fn zirImport(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError! |
| 3900 | 3900 | defer tracy.end(); |
| 3901 | 3901 | |
| 3902 | 3902 | const mod = sema.mod; |
| 3903 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 3903 | const inst_data = sema.code.instructions.items(.data)[inst].str_tok; | |
| 3904 | 3904 | const src = inst_data.src(); |
| 3905 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 3906 | const operand = try sema.resolveConstString(block, operand_src, inst_data.operand); | |
| 3905 | const operand = inst_data.get(sema.code); | |
| 3907 | 3906 | |
| 3908 | 3907 | const file = mod.importFile(block.getFileScope().pkg, operand) catch |err| switch (err) { |
| 3909 | 3908 | error.ImportOutsidePkgPath => { |
src/Zir.zig+3-3| ... | ... | @@ -377,8 +377,8 @@ pub const Inst = struct { |
| 377 | 377 | /// Implements the `@hasDecl` builtin. |
| 378 | 378 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 379 | 379 | has_decl, |
| 380 | /// `@import(operand)`. | |
| 381 | /// Uses the `un_node` field. | |
| 380 | /// Implements the `@import` builtin. | |
| 381 | /// Uses the `str_tok` field. | |
| 382 | 382 | import, |
| 383 | 383 | /// Integer literal that fits in a u64. Uses the int union value. |
| 384 | 384 | int, |
| ... | ... | @@ -1699,7 +1699,6 @@ const Writer = struct { |
| 1699 | 1699 | .load, |
| 1700 | 1700 | .ensure_result_used, |
| 1701 | 1701 | .ensure_result_non_error, |
| 1702 | .import, | |
| 1703 | 1702 | .ptrtoint, |
| 1704 | 1703 | .ret_node, |
| 1705 | 1704 | .set_eval_branch_quota, |
| ... | ... | @@ -1871,6 +1870,7 @@ const Writer = struct { |
| 1871 | 1870 | .enum_literal, |
| 1872 | 1871 | .decl_ref_named, |
| 1873 | 1872 | .decl_val_named, |
| 1873 | .import, | |
| 1874 | 1874 | => try self.writeStrTok(stream, inst), |
| 1875 | 1875 | |
| 1876 | 1876 | .func => try self.writeFunc(stream, inst, false), |