Backport "Only rename method type params shadowing enclosing class type params" to 3.8.0#24809
Merged
WojciechMazur merged 6 commits intorelease-3.8.0from Dec 22, 2025
Merged
Conversation
d12dfa1 to
28795af
Compare
Previously, method type parameters were always renamed if they had the same name as any class type parameter, regardless of whether the class type parameter was actually used in the method signature. As a result, we rename methods's type params for unnecessary names like: #24671 (Note that renaming actually doesn't cause binary incompatibility, and this change is just for make generic signature a bit clear and silence false-positive MIMA reporting). For example, in an example below, the Scala compiler rename the generic signature of `bar` to something like `bar[T1](x: T1): T1` because `T` is used by `Foo[T]`. However, this is unnessary rename because none of T in method signature refer the `T` of `Foo[T]`. ```scala class Foo[T]: def bar[T](x: T): T = ??? ``` This commit makes the renaming conditional: Method type parameters are only renamed when - (1) A class type parameter is referenced in the method signature, and - (2) That class type parameter is shadowed by a method type parameter [Cherry-picked a93c849]
[Cherry-picked 3d4d397]
Co-authored-by: Lukas Rytz <lukas.rytz@gmail.com> [Cherry-picked 7cc63d4]
Move isTypeParameterInMethSig as a local function and simplify it: collecting method type parameters by checking owner directly instead of searching the initialSymbol's typeParams list. [Cherry-picked e7fa00c]
Add test cases for nested class generic signatures when method type parameters shadow enclosing class type parameters. The tests verify that Scala 3 correctly handles type parameter name conflicts in nested generic classes by renaming method-level type parameters to avoid clashing with outer class type parameters. Closes #24619 [Cherry-picked 1e392ee]
f58372e to
4c0c3a1
Compare
Base automatically changed from
release-3.8.0_backport-24754
to
release-3.8.0
December 22, 2025 11:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports #24684 to the 3.8.0-RC4.
PR submitted by the release tooling.
[skip ci]