aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_const.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-10-31 09:13:10 +0000
committergingerBill <gingerBill@users.noreply.github.com>2025-10-31 09:13:10 +0000
commitf5d080789fbd5e10fc1c58fa960e6c382f500bf1 (patch)
treeb699f3cc7c3478b0a290f0e95a9661882f39f6d0 /src/llvm_backend_const.cpp
parentd062203ff98d2886d41de1734da67ac931b9d765 (diff)
Fix `union(T){}` constant initialization
Diffstat (limited to 'src/llvm_backend_const.cpp')
-rw-r--r--src/llvm_backend_const.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp
index a7117fe0b..952427dac 100644
--- a/src/llvm_backend_const.cpp
+++ b/src/llvm_backend_const.cpp
@@ -691,8 +691,13 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, lb
} else if (bt->Union.variants.count == 1) {
if (value.kind == ExactValue_Compound) {
ast_node(cl, CompoundLit, value.value_compound);
- if (cl->elems.count == 0 && cl->type == nullptr) {
- return lb_const_nil(m, original_type);
+ if (cl->elems.count == 0) {
+ if (cl->type == nullptr) {
+ return lb_const_nil(m, original_type);
+ }
+ if (are_types_identical(type_of_expr(cl->type), original_type)) {
+ return lb_const_nil(m, original_type);
+ }
}
}