Skip to content

objc: add explicit-class super sends - #534

Merged
hajimehoshi merged 4 commits into
mainfrom
codex/objc-super-dispatch
Sep 24, 2026
Merged

hajimehoshi merged 4 commits into
mainfrom
codex/objc-super-dispatch

Conversation

@hajimehoshi

Copy link
Copy Markdown
Member

What issue is this addressing?

Closes #533

What type of issue is this addressing?

bug

What this PR does | solves

An override that calls SendSuper can recursively reenter itself when the
receiver inherits the override, because dispatch uses the receiver's
runtime class instead of the class defining the method.

Add SendSuper1 and SendSuper2, each as an ID method and a generic helper.
SendSuper1 invokes objc_msgSendSuper and starts lookup in the supplied
superclass. SendSuper2 invokes objc_msgSendSuper2 and starts lookup in
the supplied defining class's superclass. Deprecate SendSuper while
preserving its behavior for compatibility; callers must migrate to an
explicit-class helper to handle inherited overrides correctly.

Add regression tests for direct and inherited calls, receiver and
argument forwarding, return values, and amd64 struct-return dispatch.
Update examples, including a three-level hierarchy showing the class
arguments required by the two helpers.

Validation:

  • go test ./... on macOS arm64
  • GOARCH=amd64 CGO_ENABLED=0 go test ./objc on macOS
  • Executed the updated hierarchy example separately after its final edit

Authored by Codex (OpenAI), on behalf of @hajimehoshi.

Copilot AI lite review requested due to automatic review settings September 22, 2026 15:07
@hajimehoshi

Copy link
Copy Markdown
Member Author

@TotallyGamerJet PTAL

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

The macOS test hard-codes clang and should resolve or skip unavailable configured compilers.

Review effort: Lite
Findings: None

What changed in this PR

Adds explicit-class Objective-C super-send helpers to prevent recursive dispatch through inherited overrides while preserving legacy behavior.

Changes:

  • Adds SendSuper1 and SendSuper2 APIs and generic helpers.
  • Adds dispatch, inheritance, forwarding, and struct-return regression tests.
  • Updates examples to use explicit class anchors.
File Summary
objc/​testdata/​super.m Adds Objective-C struct-return fixtures.
objc/​super_darwin_test.go Adds super-dispatch and ABI regression coverage.
objc/​objc_runtime_darwin.go Implements explicit super-dispatch APIs.
objc/​objc_runtime_darwin_test.go Updates API tests and examples.
examples/​objc/​main_darwin.go Migrates the example to explicit dispatch.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Add SendSuper1 and SendSuper2 methods and generic helpers matching
objc_msgSendSuper and objc_msgSendSuper2. Explicit class arguments let
inherited overrides dispatch to their defining class's superclass
without recursively reentering the override.

Deprecate SendSuper while preserving its existing behavior. Cover
direct and inherited calls, receiver and argument forwarding, and
struct returns, including the amd64 stret path. Update examples to
show the different class arguments in a three-level hierarchy.

Closes #533

Co-Authored-By: Codex <noreply@openai.com>
@hajimehoshi

Copy link
Copy Markdown
Member Author

I've added an explanation about the background #533 (comment)

Apparently SendSuper2 might be redundant as SendSuper1 can already represent the same thing. I'm happy to remove SendSuper2 if you think it's better.

Comment thread objc/objc_runtime_darwin_test.go Outdated
Add an ID.SendSuper1 example showing direct and inherited receivers
in a three-level class hierarchy. Keep the ID.SendSuper2 example
focused on its own method and defining-class argument.

Co-Authored-By: Codex <noreply@openai.com>
Comment thread examples/objc/main_darwin.go Outdated
Comment thread objc/objc_runtime_darwin_test.go Outdated
Comment thread objc/objc_runtime_darwin_test.go Outdated
Comment thread objc/objc_runtime_darwin_test.go Outdated
Comment thread objc/objc_runtime_darwin.go Outdated
Comment thread objc/super_darwin_test.go
hajimehoshi and others added 2 commits September 24, 2026 00:30
Remove SendSuper1 and its runtime bindings. SendSuper2 covers
Objective-C super dispatch using the defining class directly,
without a separate superclass lookup.

Update examples and regression tests to use SendSuper2, retaining
coverage for inherited overrides and struct returns. Keep the
legacy SendSuper helpers deprecated and behavior-compatible.

Co-Authored-By: Codex <noreply@openai.com>
Clarify the three-level inheritance example and the defining-class
argument to SendSuper2. Simplify the dispatch test by removing its
mode loop and conditional dispatch, while retaining argument and
receiver forwarding, return-value, and compatibility checks.

Co-Authored-By: Codex <noreply@openai.com>
Comment thread objc/objc_runtime_darwin.go

@TotallyGamerJet TotallyGamerJet left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@hajimehoshi
hajimehoshi merged commit 440e526 into main Sep 24, 2026
50 checks passed
@hajimehoshi
hajimehoshi deleted the codex/objc-super-dispatch branch September 24, 2026 16:30
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.

objc: SendSuper recursively reenters inherited overrides

3 participants