diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-23 11:14:11 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-23 11:14:11 -0700 |
| commit | 183ee0965fac6322651666834776d9832cc95ddd (patch) | |
| tree | 3d92ed486046259fcdb110e7c2570fcdc1b2900b /src/AstGen.zig | |
| parent | 0262dda9b82ab75c7f35908456e82545a5781b99 (diff) | |
| download | zig-183ee0965fac6322651666834776d9832cc95ddd.tar.gz zig-183ee0965fac6322651666834776d9832cc95ddd.zip | |
AstGen: compile error for unable to infer array size
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 996cc4d995..9b957a8d4f 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2455,9 +2455,16 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !Z const astgen = gz.astgen; const tree = &astgen.file.tree; const node_datas = tree.nodes.items(.data); + const node_tags = tree.nodes.items(.tag); + const main_tokens = tree.nodes.items(.main_token); - // TODO check for [_]T - const len = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].lhs); + const len_node = node_datas[node].lhs; + if (node_tags[len_node] == .identifier and + mem.eql(u8, tree.tokenSlice(main_tokens[len_node]), "_")) + { + return astgen.failNode(len_node, "unable to infer array size", .{}); + } + const len = try expr(gz, scope, .{ .ty = .usize_type }, len_node); const elem_type = try typeExpr(gz, scope, node_datas[node].rhs); const result = try gz.addBin(.array_type, len, elem_type); @@ -2468,9 +2475,17 @@ fn arrayTypeSentinel(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.I const astgen = gz.astgen; const tree = &astgen.file.tree; const node_datas = tree.nodes.items(.data); + const node_tags = tree.nodes.items(.tag); + const main_tokens = tree.nodes.items(.main_token); const extra = tree.extraData(node_datas[node].rhs, ast.Node.ArrayTypeSentinel); - const len = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].lhs); + const len_node = node_datas[node].lhs; + if (node_tags[len_node] == .identifier and + mem.eql(u8, tree.tokenSlice(main_tokens[len_node]), "_")) + { + return astgen.failNode(len_node, "unable to infer array size", .{}); + } + const len = try expr(gz, scope, .{ .ty = .usize_type }, len_node); const elem_type = try typeExpr(gz, scope, extra.elem_type); const sentinel = try expr(gz, scope, .{ .ty = elem_type }, extra.sentinel); |
