Commit 5d00023
committed
cgen: fix sumtype string-rvalue cast, ?&T == nil unwrap, and generic default interface field
Fixes three cgen bugs:
- #27548: casting a string rvalue (slice `s[a..b]` or concat) into a sumtype
emitted `&<rvalue>`, which strict C compilers reject. `is_lvalue()` reports a
slice as an lvalue, so the cast took a bare address instead of materializing
it. Treat a slice as an rvalue so the sumtype cast uses the ADDR macro.
- #27549: unwrapping an option-of-pointer field (`?&T`) via a `== nil`/`== none`
check emitted one too many dereferences (`**(T**)(data)` instead of
`*(T**)(data)`). The single-deref path was gated on `g.left_is_opt`, which is
only set in the smartcast (`:=`) form. The option's `.data` buffer holds a
single `&T`, so one deref is always correct for `?&T`, independent of that flag.
- #27550: a generic struct used as the default value of an interface-typed field
in a generic wrapper left a leftover unresolved-generic variant (`Text[T]`) in
the interface's types list, which the interface auto-str dispatch emitted as
broken C (`Text_T_T`, undeclared `_..._index`). Skip unresolved-generic struct
variants in gen_str_for_interface, mirroring the existing skip in
interface_table(). The struct init itself already monomorphizes correctly.1 parent d56f20f commit 5d00023
5 files changed
Lines changed: 115 additions & 3 deletions
File tree
- vlib/v
- gen/c
- tests
- casts
- generics
- options
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
442 | 451 | | |
443 | 452 | | |
444 | 453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5174 | 5174 | | |
5175 | 5175 | | |
5176 | 5176 | | |
5177 | | - | |
| 5177 | + | |
| 5178 | + | |
| 5179 | + | |
| 5180 | + | |
5178 | 5181 | | |
5179 | 5182 | | |
5180 | 5183 | | |
| |||
7984 | 7987 | | |
7985 | 7988 | | |
7986 | 7989 | | |
7987 | | - | |
7988 | | - | |
| 7990 | + | |
| 7991 | + | |
| 7992 | + | |
| 7993 | + | |
| 7994 | + | |
| 7995 | + | |
| 7996 | + | |
7989 | 7997 | | |
7990 | 7998 | | |
7991 | 7999 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
0 commit comments