Skip to content

Bind Self to the conformance target; add ce.conformsTo — Fix #362 - #366

Merged
arnog merged 2 commits into
cortex-js:mainfrom
enumeratio:protocol-self-target
Sep 30, 2026
Merged

arnog merged 2 commits into
cortex-js:mainfrom
enumeratio:protocol-self-target

Conversation

@enumeratio

Copy link
Copy Markdown
Contributor

Fix #362

  • Self in a protocol member's signature now binds to the conformance target that dispatch selects for the receiver (the most specific applicable edge, as bestCandidates picks it), not the receiver's own static type. With Compare: "(Self, Self) -> number" on real, Compare(5, 1/2) and Compare(3, 2.5) were rejected while the reverse orders passed; all four now pass, both at canonicalization and at run time, and a -> Self result binds the same way. Arguments are still checked against the target, not a join of their types, so a string argument or a non-conforming nominal type is still refused. Compile already grounded Self at the target, so it's unchanged. Appendix A of TYPE_SYSTEM_ROADMAP.md is updated.
  • ce.conformsTo(type, protocol) is the public counterpart of the resolver's internal conformsTo, including conditional conformances. It sits next to declareProtocol, and api.md is regenerated.

Protocol refinement is left as a separate exploration, as you suggested.

…rgument's static type; update Appendix A and add mixed-subtype regression tests. Part of cortex-js#362
…rnal conformance oracle; regenerate api.md. Part of cortex-js#362
@enumeratio

Copy link
Copy Markdown
Contributor Author

Pushed a review pass:

  • Added compiled-lane tests for the mixed-subtype case to protocol-dispatch-compile.test.ts: difference(5, 1/2), difference(1/2, 5) and the float pairs compile and agree with .N(). Main fails the two orders where the receiver is the narrower type.
  • Rewrote the new comments and the conformsTo doc to state the current rule, without the history or bare design references, and regenerated api.md.

This PR doesn't slow member calls on its own. Combined with #365 they stay at #365's cost.

@arnog
arnog merged commit 6ecd558 into cortex-js:main Sep 30, 2026
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

A protocol member's Self binds to the first argument's type, so mixing subtypes of the conforming type is rejected

2 participants