Skip to content

Conversation

@WojciechMazur
Copy link
Contributor

Backports #24684 to the 3.8.0-RC4.

PR submitted by the release tooling.
[skip ci]

@WojciechMazur WojciechMazur force-pushed the release-3.8.0_backport-24754 branch from d12dfa1 to 28795af Compare December 22, 2025 11:02
@WojciechMazur WojciechMazur requested a review from a team as a code owner December 22, 2025 11:02
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]
Co-authored-by: Lukas Rytz <[email protected]>

[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]
@WojciechMazur WojciechMazur force-pushed the release-3.8.0_backport-24684 branch from f58372e to 4c0c3a1 Compare December 22, 2025 11:03
Base automatically changed from release-3.8.0_backport-24754 to release-3.8.0 December 22, 2025 11:05
@WojciechMazur WojciechMazur merged commit 5fcf49a into release-3.8.0 Dec 22, 2025
10 of 17 checks passed
@WojciechMazur WojciechMazur deleted the release-3.8.0_backport-24684 branch December 22, 2025 11:05
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.

3 participants