fix: #24765 SAM conversion for extension method from self-based types#25637
fix: #24765 SAM conversion for extension method from self-based types#25637halotukozak wants to merge 1 commit intoscala:mainfrom
Conversation
…thod" for Self-based type classes
There was a problem hiding this comment.
Pull request overview
Fixes SAM conversion for extension methods in self-based type classes by ensuring type members are entered into the anonymous class scope early enough for override-resolution to see type aliases (e.g., type Self = Int), and adds a regression test for #24765.
Changes:
- Adjust anonymous class generation to enter synthetic type members before creating term forwarders (so
allOverriddenSymbolscan match signatures through aliases). - Add
tests/pos/i24765.scalaregression test coveringgiven Int is B = x => xwhereBuses aSelftype member.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/pos/i24765.scala | Adds a positive regression test for SAM conversion with Self-based extension methods. |
| compiler/src/dotty/tools/dotc/ast/tpd.scala | Reorders construction to enter type members before generating forwarder methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -398,8 +398,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { | |||
| if !overridden.is(Deferred) then fwdMeth.setFlag(Override) | |||
| DefDef(fwdMeth, ref(fn).appliedToArgss(_)) | |||
| } | |||
There was a problem hiding this comment.
This code relies on evaluation order: typeMembers are entered via .entered before calling fwdMeth.allOverriddenSymbols in forwarder, otherwise overridden-signature matching can miss type aliases (as in #24765). Please add a short comment (or refactor to make the ordering/side effect explicit) so a future cleanup doesn’t accidentally revert the fix by inlining/reordering the maps.
| } | |
| } | |
| // Important: `typeMembers` must be entered before calling `allOverriddenSymbols` in `forwarder`, | |
| // otherwise overridden-signature matching can miss type aliases (see scala/bug#24765). |
There was a problem hiding this comment.
I am not sure of the convention in this repo. I will commit this suggestion if the human reviewer asks for it
Fixes #24765
Enter type members into the anonymous class scope before creating term forwarders, so allOverriddenSymbols can resolve type aliases (like Self = Int) when matching method signatures.
How much have you relied on LLM-based tools in this contribution?
Claude helped me find the root cause.
How was the solution tested?
i24765.scalaaddedAdditional notes