Browse Source

Fix `Union{}`

gingerBill 2 weeks ago
parent
commit
35a32d41e0
1 changed files with 10 additions and 0 deletions
  1. 10 0
      src/llvm_backend_const.cpp

+ 10 - 0
src/llvm_backend_const.cpp

@@ -885,6 +885,16 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
 
 
 			i64 block_size = bt->Union.variant_block_size;
 			i64 block_size = bt->Union.variant_block_size;
 
 
+			if (are_types_identical(value_type, original_type)) {
+				if (value.kind == ExactValue_Compound) {
+					ast_node(cl, CompoundLit, value.value_compound);
+					GB_ASSERT(cl->elems.count == 0);
+					return lb_const_nil(m, original_type);
+				}
+
+				GB_PANIC("%s vs %s", type_to_string(value_type), type_to_string(original_type));
+			}
+
 			lbValue cv = lb_const_value(m, value_type, value, cc, value_type);
 			lbValue cv = lb_const_value(m, value_type, value, cc, value_type);
 			Type *variant_type = cv.type;
 			Type *variant_type = cv.type;