Skip to content

Commit 44f38b0

Browse files
committedJan 31, 2018
fix assertion fail when using global var number literal
closes #697
1 parent 40ca39d commit 44f38b0

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed
 

‎src/analyze.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -3295,6 +3295,10 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
32953295
is_const, init_val, &tld_var->base);
32963296
tld_var->var->linkage = linkage;
32973297

3298+
if (implicit_type != nullptr && type_is_invalid(implicit_type)) {
3299+
tld_var->var->value->type = g->builtin_types.entry_invalid;
3300+
}
3301+
32983302
if (var_decl->align_expr != nullptr) {
32993303
if (!analyze_const_align(g, tld_var->base.parent_scope, var_decl->align_expr, &tld_var->var->align_bytes)) {
33003304
tld_var->var->value->type = g->builtin_types.entry_invalid;

‎test/compile_errors.zig

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
const tests = @import("tests.zig");
22

33
pub fn addCases(cases: &tests.CompileErrorContext) void {
4+
cases.add("use invalid number literal as array index",
5+
\\var v = 25;
6+
\\export fn entry() void {
7+
\\ var arr: [v]u8 = undefined;
8+
\\}
9+
, ".tmp_source.zig:1:1: error: unable to infer variable type");
10+
411
cases.add("duplicate struct field",
512
\\const Foo = struct {
613
\\ Bar: i32,

0 commit comments

Comments
 (0)
Please sign in to comment.