Skip to content

checker,cgen: allow embedded interface upcasts#26772

Merged
JalonSolov merged 1 commit intovlang:masterfrom
vincenzopalazzo:codex/fix-26759-implicit-cast
Mar 31, 2026
Merged

checker,cgen: allow embedded interface upcasts#26772
JalonSolov merged 1 commit intovlang:masterfrom
vincenzopalazzo:codex/fix-26759-implicit-cast

Conversation

@vincenzopalazzo
Copy link
Copy Markdown
Contributor

Summary

  • allow implicit interface-to-interface upcasts when the source interface embeds the target interface
  • generate implicit interface conversions in cgen the same way explicit as casts do
  • make interface type-name helpers return string so minimal interface cast programs do not depend on tos3
  • add a regression test for fn-call, assignment, and explicit as cases from implicit cast inconsistency #26759

Root cause

type_implements rejected 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 explicit as casts, so implicit conversions were passed through as the wrong interface type.

Verification

  • ./vnew vlib/v/tests/interfaces/interface_embedding_implicit_upcast_test.v
  • exact issue reproducer from implicit cast inconsistency #26759 now compiles with ./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.v

Notes

  • ./vnew -silent test vlib/v/ is not locally clean in this workspace because of unrelated pre-existing worktree changes in vlib/v/checker/containers.v, vlib/v/gen/c/fn.v, and vlib/v/tests/interface_string_ref_arg_test.v.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread vlib/v/gen/c/cgen.v
@JalonSolov
Copy link
Copy Markdown
Collaborator

Close/re-open for CI run.

@JalonSolov JalonSolov closed this Mar 30, 2026
@JalonSolov JalonSolov reopened this Mar 30, 2026
@JalonSolov
Copy link
Copy Markdown
Collaborator

Several conflicts to resolve.

@StunxFS StunxFS changed the title fix: allow embedded interface upcasts checker,cgen: allow embedded interface upcasts Mar 30, 2026
Copy link
Copy Markdown
Contributor Author

@JalonSolov Fixed in 6e6d0ed. Merged current master into this branch to resolve the conflicts and reran local verification on top of the merge (vlib/v/tests/interfaces/interface_embedding_implicit_upcast_test.v, vlib/v/tests/interfaces/interface_runtime_conversions_test.v, vlib/v/gen/c/coutput_test.v, vlib/v/compiler_errors_test.v, and test vlib/v/; the VLS tests in the broad run needed the repo root on PATH because they shell out to v directly, and they passed after rerunning under that expected local setup).

@JalonSolov
Copy link
Copy Markdown
Collaborator

One more conflict (due to other PR merge).

@vincenzopalazzo
Copy link
Copy Markdown
Contributor Author

@JalonSolov Fixed in 4c7deb9. Merged current master into this branch to resolve the typeof_test.v conflict (upstream landed an expanded version of the #26704 typeof test that overlapped with the helper our branch had; took the upstream version since it subsumes ours). Reran local verification: all 80 interface tests, typeof_test.v, coutput_test.v, and compiler_errors_test.v pass.

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>
@vincenzopalazzo vincenzopalazzo force-pushed the codex/fix-26759-implicit-cast branch from 4c7deb9 to 0ecfb00 Compare March 31, 2026 07:41
@vincenzopalazzo
Copy link
Copy Markdown
Contributor Author

@JalonSolov Squashed all commits into a single one and rebased on current master (0ecfb00). History is clean now -- one commit, no merge commits, no conflicts.

@JalonSolov JalonSolov merged commit e8d0714 into vlang:master Mar 31, 2026
89 of 90 checks passed
medvednikov pushed a commit that referenced this pull request Apr 4, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants