mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
fix missing check on extern variables with no type
This commit is contained in:
parent
597a363673
commit
5667a21b1e
@ -4012,6 +4012,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
|
||||
} else if (!is_extern) {
|
||||
add_node_error(g, source_node, buf_sprintf("variables must be initialized"));
|
||||
implicit_type = g->builtin_types.entry_invalid;
|
||||
} else if (explicit_type == nullptr) {
|
||||
// extern variable without explicit type
|
||||
add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
|
||||
implicit_type = g->builtin_types.entry_invalid;
|
||||
}
|
||||
|
||||
ZigType *type = explicit_type ? explicit_type : implicit_type;
|
||||
|
||||
@ -2,6 +2,15 @@ const tests = @import("tests.zig");
|
||||
const std = @import("std");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add("extern variable has no type",
|
||||
\\extern var foo;
|
||||
\\pub export fn entry() void {
|
||||
\\ foo;
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
"tmp.zig:1:1: error: unable to infer variable type",
|
||||
});
|
||||
|
||||
cases.add("@src outside function",
|
||||
\\comptime {
|
||||
\\ @src();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user