Skip to content

Commit 0705749

Browse files
committed
Don't rely on JavaMethodType to use Java signatures
Before this commit, SingleDenotation#signature simply delegated to MethodOrPoly#signature which used Java signatures for JavaMethodType and non-Java signatures otherwise. As a first step towards getting rid of JavaMethodType, this commit changes this to make SingleDenotation#signature itself responsible for using Java signatures.
1 parent 463448f commit 0705749

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,11 +582,23 @@ object Denotations {
582582
*/
583583
def prefix: Type = NoPrefix
584584

585+
/** Either the Scala or Java signature of the info, depending on where the
586+
* symbol is defined.
587+
*
588+
* Invariants:
589+
* - Before erasure, the signature of a denotation is always equal to the
590+
* signature of its corresponding initial denotation.
591+
* - Two distinct overloads will have SymDenotations with distinct
592+
* signatures (the SELECTin tag in Tasty relies on this to refer to an
593+
* overload unambiguously). Note that this only applies to
594+
* SymDenotations, in general we cannot assume that distinct
595+
* SingleDenotations will have distinct signatures (cf #9050).
596+
*/
585597
final def signature(using Context): Signature =
586-
if (isType) Signature.NotAMethod // don't force info if this is a type SymDenotation
598+
if (isType) Signature.NotAMethod // don't force info if this is a type denotation
587599
else info match {
588-
case info: MethodicType =>
589-
try info.signature
600+
case info: MethodOrPoly =>
601+
try info.signature(isJava = symbol.is(JavaDefined))
590602
catch { // !!! DEBUG
591603
case scala.util.control.NonFatal(ex) =>
592604
report.echo(s"cannot take signature of $info")

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,12 +3405,12 @@ object Types {
34053405
mySignature
34063406
end signature
34073407

3408+
/** The Scala signature of this method. Note that two distinct Java method
3409+
* overloads may have the same Scala signature, the other overload of
3410+
* `signature` can be used to avoid ambiguity if necessary.
3411+
*/
34083412
final override def signature(using Context): Signature =
3409-
def isJava(tp: Type): Boolean = tp match
3410-
case tp: PolyType => isJava(tp.resultType)
3411-
case tp: MethodType => tp.isJavaMethod
3412-
case _ => false
3413-
signature(isJava = isJava(this))
3413+
signature(isJava = false)
34143414

34153415
final override def hashCode: Int = System.identityHashCode(this)
34163416

0 commit comments

Comments
 (0)