checker,cgen: allow embedded interface upcasts#26772
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3b3f7c581b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Close/re-open for CI run. |
|
Several conflicts to resolve. |
|
@JalonSolov Fixed in 6e6d0ed. Merged current |
|
One more conflict (due to other PR merge). |
|
@JalonSolov Fixed in 4c7deb9. Merged current |
Add support for implicit upcasting when an interface embeds another interface (including transitive chains like Dense -> Solid -> Base). - checker: `interface_embeds_interface_recursive` walks the embed tree to accept the upcast instead of erroring with "cannot implement interface with a different interface". - cgen: `expr_with_cast` emits `I_<Got>_as_I_<Exp>(...)` conversion calls for interface-to-interface casts, skipping the branch when either side carries `shared_f` so the existing shared-container path handles those. - cgen/fn: `v_typeof_interface_` helpers now return `string` (via `_S(...)`) instead of `char *`, fixing charptr/string mismatches. - vfmt/parser: preserve attribute call syntax (`@[attr(...)]`) through format round-trips. - closure: keep ppc64 bootstrap-compatible by guarding arch-specific trampoline code. Fixes vlang#26759. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4c7deb9 to
0ecfb00
Compare
|
@JalonSolov Squashed all commits into a single one and rebased on current |
Add support for implicit upcasting when an interface embeds another interface (including transitive chains like Dense -> Solid -> Base). - checker: `interface_embeds_interface_recursive` walks the embed tree to accept the upcast instead of erroring with "cannot implement interface with a different interface". - cgen: `expr_with_cast` emits `I_<Got>_as_I_<Exp>(...)` conversion calls for interface-to-interface casts, skipping the branch when either side carries `shared_f` so the existing shared-container path handles those. - cgen/fn: `v_typeof_interface_` helpers now return `string` (via `_S(...)`) instead of `char *`, fixing charptr/string mismatches. - vfmt/parser: preserve attribute call syntax (`@[attr(...)]`) through format round-trips. - closure: keep ppc64 bootstrap-compatible by guarding arch-specific trampoline code. Fixes #26759. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
ascasts dostringso minimal interface cast programs do not depend ontos3ascases from implicit cast inconsistency #26759Root cause
type_implementsrejected all interface-to-interface implicit conversions, even when the source interface explicitly embedded the target one. The C backend also only handled interface-to-interface conversions for explicitascasts, so implicit conversions were passed through as the wrong interface type.Verification
./vnew vlib/v/tests/interfaces/interface_embedding_implicit_upcast_test.v./vnew./vnew vlib/v/tests/interfaces/interface_runtime_conversions_test.v./vnew -silent vlib/v/compiler_errors_test.v./vnew -silent vlib/v/gen/c/coutput_test.vNotes
./vnew -silent test vlib/v/is not locally clean in this workspace because of unrelated pre-existing worktree changes invlib/v/checker/containers.v,vlib/v/gen/c/fn.v, andvlib/v/tests/interface_string_ref_arg_test.v.