authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-07 23:31:38+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-07-08 03:09:41+00:00
log5667a21b1e7b8aa2dfcefed81d2b594029a116db
tree07ce6306793ab5486b92d873987030c7f4601c32
parent597a36367305cdb63ffe25af707d708ef9376a7a

fix missing check on extern variables with no type


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) {
40124012 } else if (!is_extern) {
40134013 add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
40144014 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;
40154019 }
40164020
40174021 ZigType *type = explicit_type ? explicit_type : implicit_type;
test/compile_errors.zig+9
......@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
22const std = @import("std");
33
44pub 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
514 cases.add("@src outside function",
615 \\comptime {
716 \\ @src();