string -> ""
bool -> false
bit_set -> {}
anything with a nil -> nil
everything else -> {}
This adds a hint for structs, arrays, matrices, bit_fields, `#no_nil` unions, `rawptr`, `typeid`, the four string types and `bool`. A `bit_set` now suggests `{}` rather than `nil`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`convert_untyped_error` sets `operand->mode = Addressing_Invalid` as its last
statement. Every call site assigns it on the line just before the call too,
which is dead except for one side effect: it suppresses the `Did you want
'nil'?` hint, gated on `operand->mode == Addressing_Constant`.
PR 7403 removed the assignment at the union call site. This removes the
remaining 10 in `convert_to_typed`.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The hack made `0` legal against `os.Error` by blanking the constant's
`ExactValue` via `update_untyped_expr_value`, which is a silent no-op when
the expression has not been registered as an untyped expression yet. Since
#7087, `check_expr_base` calls `convert_to_typed` before `add_untyped` runs,
so the blanking is lost and the backend receives a constant typed `os.Error`
still holding integer `0` with no variant type, tripping
`GB_ASSERT_MSG(value_type != nullptr)` in `lb_const_value`.
Also drop the redundant `operand->mode = Addressing_Invalid;` before the
union `convert_untyped_error` call, which revives the `Did you want 'nil'?`
hint, and guard that hint on `type_has_nil` and an Integer/Float zero.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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#6100Fix#6699Fix#6895Fix#6896Fix#6897Fix#7036Fix#7083Fix#7091