Skip to content

Commit 1f6fa54

Browse files
tanishikinglolgab
authored andcommitted
Add regression tests for #24619
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
1 parent 7a216a6 commit 1f6fa54

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

compiler/test/dotc/pos-test-pickling.excludelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ i11982a.scala
3434
i17255
3535
i17735.scala
3636
i24134
37+
i24134-nested
3738

3839
# Tree is huge and blows stack for printing Text
3940
i7034.scala
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
noShadow: public scala.Tuple3<T, U, V> Outer$Middle$Inner.noShadow(T,U,V)
2+
shadowOuter: public <T1> T Outer$Middle$Inner.shadowOuter()
3+
shadowMiddle: public <U1> U Outer$Middle$Inner.shadowMiddle()
4+
shadowInner: public <V1> V Outer$Middle$Inner.shadowInner()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Outer[T]:
2+
def outerValue: T = ???
3+
4+
class Middle[U]:
5+
def middleValue: U = ???
6+
7+
class Inner[V]:
8+
def innerValue: V = ???
9+
def noShadow(x: T, y: U, z: V): (T, U, V) = (x, y, z)
10+
def shadowOuter[T] = outerValue
11+
def shadowMiddle[U] = middleValue
12+
def shadowInner[V] = innerValue
13+
14+
@main def Test(): Unit =
15+
val innerMethods = classOf[Outer[_]].getDeclaredClasses()
16+
.find(_.getName.contains("Middle")).get.getDeclaredClasses()
17+
.find(_.getName.contains("Inner")).get.getDeclaredMethods()
18+
19+
printMethodSig(innerMethods, "noShadow")
20+
printMethodSig(innerMethods, "shadowOuter")
21+
printMethodSig(innerMethods, "shadowMiddle")
22+
printMethodSig(innerMethods, "shadowInner")
23+
24+
def printMethodSig(methods: Array[java.lang.reflect.Method], name: String): Unit =
25+
methods.find(_.getName.endsWith(name)).foreach { m =>
26+
println(s"$name: ${m.toGenericString}")
27+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Container[A]:
2+
abstract class JavaPartialFunction[B] extends PartialFunction[A, B]

tests/pos/i24134-nested/Main.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Main {
2+
public static void main(String[] args) {
3+
Container<String> container = new Container<>();
4+
Container<String>.JavaPartialFunction<Integer> pf = container.new JavaPartialFunction<Integer>() {
5+
@Override
6+
public boolean isDefinedAt(String x) {
7+
return x != null && !x.isEmpty();
8+
}
9+
@Override
10+
public Integer apply(String x) {
11+
return x.length();
12+
}
13+
};
14+
}
15+
}

0 commit comments

Comments
 (0)