| author | |
| committer | |
| log | 94f977a6c12f3c5877f404c51a01b1b32c8acaa6 |
| tree | 5a5836479fe671c5e8c29e64e9ba5eb8e914ab8e |
| parent | f6ac2fa70e7e2eb5d3299dc90c581d139b0bea1b |
3 files changed, 14 insertions(+), 12 deletions(-)
src/codegen.cpp+3-1| ... | @@ -1567,7 +1567,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru | ... | @@ -1567,7 +1567,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru |
| 1567 | } | 1567 | } |
| 1568 | 1568 | ||
| 1569 | static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) { | 1569 | static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) { |
| 1570 | bool maybe_is_ptr = (maybe_type->id == TypeTableEntryIdPointer || maybe_type->id == TypeTableEntryIdFn); | 1570 | assert(maybe_type->id == TypeTableEntryIdMaybe); |
| 1571 | TypeTableEntry *child_type = maybe_type->data.maybe.child_type; | ||
| 1572 | bool maybe_is_ptr = (child_type->id == TypeTableEntryIdPointer || child_type->id == TypeTableEntryIdFn); | ||
| 1571 | if (maybe_is_ptr) { | 1573 | if (maybe_is_ptr) { |
| 1572 | return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), ""); | 1574 | return LLVMBuildICmp(g->builder, LLVMIntNE, maybe_handle, LLVMConstNull(maybe_type->type_ref), ""); |
| 1573 | } else { | 1575 | } else { |
test/cases/generics.zig+11| ... | @@ -128,6 +128,17 @@ fn aGenericFn(inline T: type, inline a: T, b: T) -> T { | ... | @@ -128,6 +128,17 @@ fn aGenericFn(inline T: type, inline a: T, b: T) -> T { |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | 130 | ||
| 131 | fn genericFnWithImplicitCast() { | ||
| 132 | @setFnTest(this); | ||
| 133 | |||
| 134 | assert(getFirstByte(u8, []u8 {13}) == 13); | ||
| 135 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); | ||
| 136 | } | ||
| 137 | fn getByte(ptr: ?&u8) -> u8 {*??ptr} | ||
| 138 | fn getFirstByte(inline T: type, mem: []T) -> u8 { | ||
| 139 | getByte((&u8)(&mem[0])) | ||
| 140 | } | ||
| 141 | |||
| 131 | // TODO const assert = @import("std").debug.assert; | 142 | // TODO const assert = @import("std").debug.assert; |
| 132 | fn assert(ok: bool) { | 143 | fn assert(ok: bool) { |
| 133 | if (!ok) | 144 | if (!ok) |
test/self_hosted.zig deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | // TODO not passing | ||
| 2 | fn genericFnWithImplicitCast() { | ||
| 3 | @setFnTest(this); | ||
| 4 | |||
| 5 | assert(getFirstByte(u8, []u8 {13}) == 13); | ||
| 6 | assert(getFirstByte(u16, []u16 {0, 13}) == 0); | ||
| 7 | } | ||
| 8 | fn getByte(ptr: ?&u8) -> u8 {*??ptr} | ||
| 9 | fn getFirstByte(inline T: type, mem: []T) -> u8 { | ||
| 10 | getByte((&u8)(&mem[0])) | ||
| 11 | } | ||