Skip to content

Commit 0872740

Browse files
committed
fix: look at the underlying of a TermRef for a getter
1 parent fe49539 commit 0872740

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ object GenericSignatures {
246246
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = unboxedVCs)
247247
else typeParamSig(ref.paramName.lastPart)
248248

249+
case ref: TermRef if ref.symbol.isGetter =>
250+
// If the type of a val is a TermRef to another val, generating the generic signature
251+
// based on the underlying type will produce the type `scala.Function0<underlying>`
252+
// The reason behind this is that during the `getters` phase, the same symbol will now
253+
// refer to the getter where the type will be now `=> <underlying>`.
254+
// Since the TermRef originally intended to capture the underlying type of a `val`,
255+
// we recover that information by directly checking the resultType of the getter.
256+
// See `tests/run/i24553.scala` for an example
257+
jsig(ref.info.resultType, toplevel = toplevel, unboxedVCs = unboxedVCs)
258+
249259
case ref: SingletonType =>
250260
// Singleton types like `x.type` need to be widened to their underlying type
251261
// For example, `def identity[A](x: A): x.type` should have signature

tests/run/i24553.check

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public boolean java.lang.Object.equals(java.lang.Object)
2+
public final native java.lang.Class<?> java.lang.Object.getClass()
3+
public native int java.lang.Object.hashCode()
4+
public int Foo.hello()
5+
public final native void java.lang.Object.notify()
6+
public final native void java.lang.Object.notifyAll()
7+
public java.lang.String java.lang.Object.toString()
8+
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
9+
public final void java.lang.Object.wait() throws java.lang.InterruptedException
10+
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
11+
public int Foo.x()

tests/run/i24553.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// scalajs: --skip
2+
class Foo:
3+
val hello = 1337
4+
val x: hello.type = ???
5+
6+
@main def Test =
7+
val mtds = classOf[Foo].getMethods().sortBy(_.getName())
8+
for mtd <- mtds do println(mtd.toGenericString())

0 commit comments

Comments
 (0)