fix compiler crash regarding type name of undefined

See #547
This commit is contained in:
Andrew Kelley 2017-10-21 13:14:10 -04:00
parent 9b91c76088
commit 175893913d
2 changed files with 7 additions and 0 deletions

View File

@ -4554,6 +4554,7 @@ static void define_builtin_types(CodeGen *g) {
{ {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefLit); TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefLit);
buf_init_from_str(&entry->name, "(undefined)"); buf_init_from_str(&entry->name, "(undefined)");
entry->zero_bits = true;
g->builtin_types.entry_undef = entry; g->builtin_types.entry_undef = entry;
} }
{ {

View File

@ -1,4 +1,5 @@
const assert = @import("std").debug.assert; const assert = @import("std").debug.assert;
const mem = @import("std").mem;
fn initStaticArray() -> [10]i32 { fn initStaticArray() -> [10]i32 {
var array: [10]i32 = undefined; var array: [10]i32 = undefined;
@ -60,3 +61,8 @@ test "assign undefined to struct with method" {
assert(foo.x == 3); assert(foo.x == 3);
} }
} }
test "type name of undefined" {
const x = undefined;
assert(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));
}