Skip to content

Commit f194388

Browse files
committed
Fix TermRefWithSignature#newLikeThis
The signature might need to be updated if the symbol has a different type as seen from the new prefix.
1 parent 44d0096 commit f194388

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
4949
loop(this.paramsSig, that.paramsSig)
5050
}
5151

52+
/** Is this siganture consistent with that signature?
53+
* This is the case if the signatures have consistent parameters
54+
* and result types.
55+
*/
56+
final def consistentWith(that: Signature): Boolean =
57+
consistentParams(that) && consistent(resSig, that.resSig)
58+
5259
/** The degree to which this signature matches `that`.
5360
* If parameter names are consistent and result types names match (i.e. they are the same
5461
* or one is a wildcard), the result is `FullMatch`.

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,8 +1867,15 @@ object Types {
18671867
}
18681868
else candidate
18691869

1870-
override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef =
1871-
fixDenot(TermRef.withSig(prefix, name, sig), prefix)
1870+
override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef = {
1871+
// If symbol exists, the new signature is the symbol's signature as seen
1872+
// from the new prefix, modulo consistency
1873+
val symSig =
1874+
if (symbol.exists) symbol.info.asSeenFrom(prefix, symbol.owner).signature
1875+
else sig
1876+
val newSig = if (sig.consistentWith(symSig)) sig else symSig
1877+
fixDenot(TermRef.withSig(prefix, name, newSig), prefix)
1878+
}
18721879

18731880
override def shadowed(implicit ctx: Context): NamedType =
18741881
fixDenot(TermRef.withSig(prefix, name.derived(ShadowedName), sig), prefix)

0 commit comments

Comments
 (0)