Skip to content

Commit 7f2ab31

Browse files
committed
Fix constant nil assignment to union of nillable types in backend
1 parent 91d923b commit 7f2ab31

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/llvm_backend_const.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
701701
}
702702
}
703703

704+
if (value_type == t_untyped_nil) {
705+
return lb_const_nil(m, original_type);
706+
}
707+
704708
Type *t = bt->Union.variants[0];
705709
lbValue cv = lb_const_value(m, t, value, cc);
706710
GB_ASSERT(LLVMIsConstant(cv.value));
@@ -741,6 +745,8 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
741745
} else if (value.kind == ExactValue_Invalid) {
742746
return lb_const_nil(m, original_type);
743747
}
748+
} else if (value_type == t_untyped_nil) {
749+
return lb_const_nil(m, original_type);
744750
}
745751

746752
GB_ASSERT_MSG(value_type != nullptr, "%s :: %s", type_to_string(original_type), exact_value_to_string(value));

0 commit comments

Comments
 (0)