Skip to content

Commit

Permalink
fix assertion fail when using global var number literal
Browse files Browse the repository at this point in the history
closes #697
  • Loading branch information
andrewrk committed Jan 31, 2018
1 parent 40ca39d commit 44f38b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/analyze.cpp
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions 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,
Expand Down

0 comments on commit 44f38b0

Please sign in to comment.