Commit 3f4d0cc
committed
Fix generic signatures for mixin forwarders conflicting type parameter names
Fixes #24134
f99dba2 started emitting Java generic signature for mixin forwarders.
However, when generating Java generic signatures for mixin forwarders,
method-level type parameters could shadow class-level type parameters with the same name.
For example, when `JavaPartialFunction[A, B]` implements
`PartialFunction1[A, B]`,
```scala
trait Function1[-T1, +R]:
def compose[A](g: A => T1): A => R = ???
trait PartialFunction[-A, +B] extends Function1[A, B]:
def compose[R](k: PartialFunction[R, A]): PartialFunction[R, B] = ???
abstract class JavaPartialFunction[A, B] extends PartialFunction[A, B]
```
the generated mixin forwarder for `compose` in Function1 was like:
```java
public abstract class JavaPartialFunction<A, B> implements scala.PartialFunction<A, B> {
public <A> scala.Function1<A, B> compose(scala.Function1<A, A>);
```
which is obviously incorrect, the type parameter `A` of
`compose[A]` is shadowed by the `A` in `JavaPartialFunction<A, B>`.
The `compose`'s type parameter should use an unique name like:
```java
public abstract class JavaPartialFunction<A, B> implements scala.PartialFunction<A, B> {
public <T> scala.Function1<T, B> compose(scala.Function1<T, A>);
```
This commit fix the problem by
- Tracks class-level type parameter names when generating
method signatures
- Renames conflicting method-level type parameters (A → A1,
A2, etc.)1 parent 7eab684 commit 3f4d0cc
File tree
4 files changed
+82
-10
lines changed- compiler
- src/dotty/tools/dotc/transform
- test/dotc
- tests/pos/i24134
4 files changed
+82
-10
lines changedLines changed: 43 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
47 | 74 | | |
48 | 75 | | |
49 | 76 | | |
| |||
133 | 160 | | |
134 | 161 | | |
135 | 162 | | |
136 | | - | |
137 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
138 | 166 | | |
139 | 167 | | |
140 | 168 | | |
141 | 169 | | |
142 | 170 | | |
143 | 171 | | |
144 | | - | |
| 172 | + | |
145 | 173 | | |
146 | 174 | | |
147 | 175 | | |
| |||
151 | 179 | | |
152 | 180 | | |
153 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
154 | 188 | | |
155 | 189 | | |
156 | 190 | | |
| |||
160 | 194 | | |
161 | 195 | | |
162 | 196 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | 197 | | |
169 | 198 | | |
170 | 199 | | |
| |||
244 | 273 | | |
245 | 274 | | |
246 | 275 | | |
247 | | - | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
248 | 281 | | |
249 | 282 | | |
250 | 283 | | |
251 | | - | |
| 284 | + | |
252 | 285 | | |
253 | 286 | | |
254 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments