commit 44f38b04b0cc374fcd377df0fe68f29c824185ff (tree)
parent 40ca39d3d5a556e3b5d7298e3a5182f4351bdd17
Author: Andrew Kelley <superjoe30@gmail.com>
Date: Wed, 31 Jan 2018 11:13:39 -0500
fix assertion fail when using global var number literal
closes #697
Diffstat:
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/src/analyze.cpp b/src/analyze.cpp
@@ -3295,6 +3295,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
is_const, init_val, &tld_var->base);
tld_var->var->linkage = linkage;
+ if (implicit_type != nullptr && type_is_invalid(implicit_type)) {
+ tld_var->var->value->type = g->builtin_types.entry_invalid;
+ }
+
if (var_decl->align_expr != nullptr) {
if (!analyze_const_align(g, tld_var->base.parent_scope, var_decl->align_expr, &tld_var->var->align_bytes)) {
tld_var->var->value->type = g->builtin_types.entry_invalid;
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
@@ -1,6 +1,13 @@
const tests = @import("tests.zig");
pub fn addCases(cases: &tests.CompileErrorContext) void {
+ cases.add("use invalid number literal as array index",
+ \\var v = 25;
+ \\export fn entry() void {
+ \\ var arr: [v]u8 = undefined;
+ \\}
+ , ".tmp_source.zig:1:1: error: unable to infer variable type");
+
cases.add("duplicate struct field",
\\const Foo = struct {
\\ Bar: i32,