Implement fixes for constant unions

Note that with this commit, casting through
multiply-nested unions is forbidden, e.g.
```
U :: union {int, V}
V :: union {bool}
x: U = true
```
does not compile.
(Previously the compiler would simply crash)

This is to avoid situations where adding variants
can lead to unexpected changes in the value.

For example if `U` is changed to have a `bool`
variant of its own:
```
U :: union {int, bool, V}
```
Then `x: U = true` would equal
`U(true)` instead of `U(V(true))`.

Single-variant unions are exempt, primarily to
improve the ergonomics of `Maybe` in cases like:
```
x: Maybe(union{int, bool}) = 1
```

Fix #6100
Fix #6699
Fix #6895
Fix #6896
Fix #6897
Fix #7036
Fix #7083
Fix #7091
This commit is contained in:
korvahkh
2026-07-22 09:58:49 -05:00
parent 7f80c7093a
commit 02246ac6fd
8 changed files with 199 additions and 139 deletions

View File

@@ -2434,7 +2434,7 @@ gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) {
if (e->Variable.is_rodata) {
cc.is_rodata = true;
}
value = lb_const_value(p->module, ast_value->tav.type, ast_value->tav.value, nullptr, cc);
value = lb_const_value(p->module, ast_value->tav.type, ast_value->tav.value, cc);
}
String mangled_name = {};