Skip to content

Commit 9b85e44

Browse files
committed
Add another test case that shadows class's type param
scala/bug#13144
1 parent 3d4d397 commit 9b85e44

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

tests/generic-java-signatures/shadowedTypeParam.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ baz: public <T> T Foo.baz(T,Foo<T>)
33
qux: public <U> U Foo.qux(U,Foo<T>)
44
quux: public <T,U> scala.Tuple2<T, U> Foo.quux(T,U,Foo<T>)
55
copy: public <T> Bar<T> Bar.copy(T)
6+
copy$default$1: public <T1> T Bar.copy$default$1()
7+
m: public <T1> T C.m()
68
compose: public <A1> scala.Function1<A1, B> JavaPartialFunction.compose(scala.Function1<A1, A>)
79
compose: public <R> scala.PartialFunction<R, B> JavaPartialFunction.compose(scala.PartialFunction<R, A>)

tests/generic-java-signatures/shadowedTypeParam.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class Foo[T]:
88
// https://github.com/scala/scala3/issues/24671
99
final case class Bar[+T](t: T)
1010

11+
// `m: public <T1> T C.m()` rather than `m: public <T> T C.m()`
12+
// that was wrong and could be crashed with
13+
// `val c = C[String]; String x = c.<Object>m();`.
14+
abstract class C[T]:
15+
def x: T
16+
def m[T] = x
17+
1118
// https://github.com/scala/scala3/issues/24134
1219
// The mixin forwarders for compose in Function1 method has signature
1320
// `def compose[A](g: A => T1): A => R`
@@ -24,10 +31,13 @@ abstract class JavaPartialFunction[A, B] extends PartialFunction[A, B]
2431

2532
val barMethods = classOf[Bar[_]].getDeclaredMethods()
2633
printMethodSig(barMethods, "copy")
27-
// copy$default$1 still have `<T1> T Bar.copy$default$1` rather than `<T> T Bar.copy$default$1`
34+
// copy$default$1 have `<T1> T Bar.copy$default$1` rather than `<T> T Bar.copy$default$1`
2835
// as reported in https://github.com/scala/scala3/issues/24671
2936
// The type parameter rename occurs because the return type T refers the enclosing class's type param T.
30-
// printMethodSig(barMethods, "copy$default$1")
37+
printMethodSig(barMethods, "copy$default$1")
38+
39+
val cMethods = classOf[C[_]].getDeclaredMethods()
40+
printMethodSig(cMethods, "m")
3141

3242
val jpfMethods = classOf[JavaPartialFunction[_, _]].getDeclaredMethods()
3343
printMethodSigs(jpfMethods, "compose")

0 commit comments

Comments
 (0)