aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-16 15:50:28 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-16 15:50:28 -0700
commitadc2aed587d009c0d112063fa0f3d03dedc9e50a (patch)
tree0e32f88c8729eadc2708af7e9d53f8517222cf96 /src/AstGen.zig
parent333a577d73cdbac420d25167a3955956af91b2eb (diff)
downloadzig-adc2aed587d009c0d112063fa0f3d03dedc9e50a.tar.gz
zig-adc2aed587d009c0d112063fa0f3d03dedc9e50a.zip
AstGen: require `@import` operand to be string literal
See #2206
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index b0f554df5c..7dde9abf61 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -4674,8 +4674,17 @@ fn builtinCall(
return rvalue(gz, scope, rl, .void_value, node);
},
.import => {
- const target = try expr(gz, scope, .none, params[0]);
- const result = try gz.addUnNode(.import, target, node);
+ const node_tags = tree.nodes.items(.tag);
+ const node_datas = tree.nodes.items(.data);
+ const operand_node = params[0];
+
+ if (node_tags[operand_node] != .string_literal) {
+ // Spec reference: https://github.com/ziglang/zig/issues/2206
+ return astgen.failNode(operand_node, "@import operand must be a string literal", .{});
+ }
+ const str_lit_token = main_tokens[operand_node];
+ const str = try gz.strLitAsString(str_lit_token);
+ const result = try gz.addStrTok(.import, str.index, str_lit_token);
return rvalue(gz, scope, rl, result, node);
},
.error_to_int => {