From 4369a1714e9e039abc09bdb095b8044ad2f5d2ff Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 8 Dec 2018 13:31:25 +0000 Subject: Fix automatic subtype casting bug --- src/ir.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 77587516d..44095a4a9 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -4581,15 +4581,14 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { Type *pst = st; st = type_deref(st); - bool st_is_ptr = st != pst; + bool st_is_ptr = is_type_pointer(src_type); st = base_type(st); Type *dt = t; bool dt_is_ptr = is_type_pointer(dt); - GB_ASSERT(is_type_struct(st) || is_type_union(st)); - String field_name = ir_lookup_subtype_polymorphic_field(proc->module->info, t, st); - // gb_printf("field_name: %.*s\n", LIT(field_name)); + GB_ASSERT(is_type_struct(st) || is_type_raw_union(st)); + String field_name = ir_lookup_subtype_polymorphic_field(proc->module->info, t, src_type); if (field_name.len > 0) { // NOTE(bill): It can be casted Selection sel = lookup_field(st, field_name, false); @@ -4614,7 +4613,11 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) { return ir_emit_deep_field_ev(proc, value, sel); } + } else { + GB_PANIC("invalid subtype cast"); } + } else { + GB_PANIC("invalid subtype cast"); } } -- cgit v1.2.3