Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,16 @@ object GenericSignatures {
jsig(erasedUnderlying, toplevel = toplevel, unboxedVCs = unboxedVCs)
else typeParamSig(ref.paramName.lastPart)

case ref: TermRef if ref.symbol.isGetter =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equivalent in TypeErasure:

private def underlyingOfTermRef(tp: TermRef)(using Context) = tp.widen match
case tpw @ MethodType(Nil) if tp.symbol.isGetter => tpw.resultType
case tpw => tpw

// If the type of a val is a TermRef to another val, generating the generic signature
// based on the underlying type will produce the type `scala.Function0<underlying>`
// The reason behind this is that during the `getters` phase, the same symbol will now
// refer to the getter where the type will be now `=> <underlying>`.
// Since the TermRef originally intended to capture the underlying type of a `val`,
// we recover that information by directly checking the resultType of the getter.
// See `tests/run/i24553.scala` for an example
jsig(ref.info.resultType, toplevel = toplevel, unboxedVCs = unboxedVCs)

case ref: SingletonType =>
// Singleton types like `x.type` need to be widened to their underlying type
// For example, `def identity[A](x: A): x.type` should have signature
Expand Down
11 changes: 11 additions & 0 deletions tests/run/i24553.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public boolean java.lang.Object.equals(java.lang.Object)
public final native java.lang.Class<?> java.lang.Object.getClass()
public native int java.lang.Object.hashCode()
public int Foo.hello()
public final native void java.lang.Object.notify()
public final native void java.lang.Object.notifyAll()
public java.lang.String java.lang.Object.toString()
public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
public final void java.lang.Object.wait() throws java.lang.InterruptedException
public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
public int Foo.x()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this fix, we would have gotten:

public scala.Function0<java.lang.Object> Foo.x()

8 changes: 8 additions & 0 deletions tests/run/i24553.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// scalajs: --skip
class Foo:
val hello = 1337
val x: hello.type = ???

@main def Test =
val mtds = classOf[Foo].getMethods().sortBy(_.getName())
for mtd <- mtds do println(mtd.toGenericString())
Loading