Skip to content

Commit

Permalink
fix compiler crash regarding type name of undefined
Browse files Browse the repository at this point in the history
See #547
  • Loading branch information
andrewrk committed Oct 21, 2017
1 parent 9b91c76 commit 1758939
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4554,6 +4554,7 @@ static void define_builtin_types(CodeGen *g) {
{
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefLit);
buf_init_from_str(&entry->name, "(undefined)");
entry->zero_bits = true;
g->builtin_types.entry_undef = entry;
}
{
Expand Down
6 changes: 6 additions & 0 deletions test/cases/undefined.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = @import("std").debug.assert;
const mem = @import("std").mem;

fn initStaticArray() -> [10]i32 {
var array: [10]i32 = undefined;
Expand Down Expand Up @@ -60,3 +61,8 @@ test "assign undefined to struct with method" {
assert(foo.x == 3);
}
}

test "type name of undefined" {
const x = undefined;
assert(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));
}

0 comments on commit 1758939

Please sign in to comment.