| author | |
| committer | |
| log | 5667a21b1e7b8aa2dfcefed81d2b594029a116db |
| tree | 07ce6306793ab5486b92d873987030c7f4601c32 |
| parent | 597a36367305cdb63ffe25af707d708ef9376a7a |
2 files changed, 13 insertions(+), 0 deletions(-)
src/analyze.cpp+4| ... | ... | @@ -4012,6 +4012,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) { |
| 4012 | 4012 | } else if (!is_extern) { |
| 4013 | 4013 | add_node_error(g, source_node, buf_sprintf("variables must be initialized")); |
| 4014 | 4014 | implicit_type = g->builtin_types.entry_invalid; |
| 4015 | } else if (explicit_type == nullptr) { | |
| 4016 | // extern variable without explicit type | |
| 4017 | add_node_error(g, source_node, buf_sprintf("unable to infer variable type")); | |
| 4018 | implicit_type = g->builtin_types.entry_invalid; | |
| 4015 | 4019 | } |
| 4016 | 4020 | |
| 4017 | 4021 | ZigType *type = explicit_type ? explicit_type : implicit_type; |
test/compile_errors.zig+9| ... | ... | @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); |
| 2 | 2 | const std = @import("std"); |
| 3 | 3 | |
| 4 | 4 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5 | cases.add("extern variable has no type", | |
| 6 | \\extern var foo; | |
| 7 | \\pub export fn entry() void { | |
| 8 | \\ foo; | |
| 9 | \\} | |
| 10 | , &[_][]const u8{ | |
| 11 | "tmp.zig:1:1: error: unable to infer variable type", | |
| 12 | }); | |
| 13 | ||
| 5 | 14 | cases.add("@src outside function", |
| 6 | 15 | \\comptime { |
| 7 | 16 | \\ @src(); |