Skip to content

Commit 1758939

Browse files
committed
fix compiler crash regarding type name of undefined
See #547
1 parent 9b91c76 commit 1758939

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/codegen.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -4554,6 +4554,7 @@ static void define_builtin_types(CodeGen *g) {
45544554
{
45554555
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefLit);
45564556
buf_init_from_str(&entry->name, "(undefined)");
4557+
entry->zero_bits = true;
45574558
g->builtin_types.entry_undef = entry;
45584559
}
45594560
{

test/cases/undefined.zig

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const assert = @import("std").debug.assert;
2+
const mem = @import("std").mem;
23

34
fn initStaticArray() -> [10]i32 {
45
var array: [10]i32 = undefined;
@@ -60,3 +61,8 @@ test "assign undefined to struct with method" {
6061
assert(foo.x == 3);
6162
}
6263
}
64+
65+
test "type name of undefined" {
66+
const x = undefined;
67+
assert(mem.eql(u8, @typeName(@typeOf(x)), "(undefined)"));
68+
}

0 commit comments

Comments
 (0)