Skip to content

Ensure names used in signatures are stable #9133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2020
Merged
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
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,16 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean
if (defn.isSyntheticFunctionClass(sym))
sigName(defn.erasedFunctionType(sym))
else
normalizeClass(sym.asClass).fullName.asTypeName
val cls = normalizeClass(sym.asClass)
val fullName =
if !ctx.erasedTypes then
// It's important to use the initial symbol to compute the full name
// because the current symbol might have a different name or owner
// and signatures are required to be stable before erasure.
cls.initial.fullName
else
cls.fullName
fullName.asTypeName
case tp: AppliedType =>
val sym = tp.tycon.typeSymbol
sigName( // todo: what about repeatedParam?
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,7 @@ object Types {
* or if there is none, the signature of the symbol. Signatures are always
* computed before erasure, since some symbols change their signature at erasure.
*/
protected def computeSignature(implicit ctx: Context): Signature =
protected[dotc] def computeSignature(implicit ctx: Context): Signature =
val lastd = lastDenotation
if lastd != null then sigFromDenot(lastd)
else if ctx.erasedTypes then computeSignature(using ctx.withPhase(ctx.erasurePhase))
Expand Down Expand Up @@ -3064,7 +3064,7 @@ object Types {
protected var mySignature: Signature = _
protected var mySignatureRunId: Int = NoRunId

protected def computeSignature(implicit ctx: Context): Signature
protected[dotc] def computeSignature(implicit ctx: Context): Signature

final override def signature(implicit ctx: Context): Signature = {
if (ctx.runId != mySignatureRunId) {
Expand Down Expand Up @@ -3357,7 +3357,7 @@ object Types {
companion.eq(ContextualMethodType) ||
companion.eq(ErasedContextualMethodType)

def computeSignature(implicit ctx: Context): Signature = {
protected[dotc] def computeSignature(implicit ctx: Context): Signature = {
val params = if (isErasedMethod) Nil else paramInfos
resultSignature.prependTermParams(params, isJavaMethod)
}
Expand Down Expand Up @@ -3592,7 +3592,7 @@ object Types {
assert(resType.isInstanceOf[TermType], this)
assert(paramNames.nonEmpty)

def computeSignature(implicit ctx: Context): Signature =
protected[dotc] def computeSignature(implicit ctx: Context): Signature =
resultSignature.prependTypeParams(paramNames.length)

override def isContextualMethod = resType.isContextualMethod
Expand Down
14 changes: 11 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,20 @@ class TreeChecker extends Phase with SymTransformer {
if (ctx.phaseId <= ctx.erasurePhase.id) {
val cur = symd.info
val initial = symd.initial.info
assert(cur.signature == initial.signature,
i"""Signature of $symd changed at phase ${ctx.phase}
val curSig = cur match {
case cur: SignatureCachingType =>
// Bypass the signature cache, it might hide a signature change
cur.computeSignature
case _ =>
cur.signature
}
assert(curSig == initial.signature,
i"""Signature of ${sym.showLocated} changed at phase ${ctx.base.squashed(ctx.phase.prev)}
|Initial info: ${initial}
|Initial sig : ${initial.signature}
|Current info: ${cur}
|Current sig : ${cur.signature}""")
|Current sig : ${curSig}
|Current cached sig: ${cur.signature}""")
}

symd
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/local-signature.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class A {
def bn(x: => Any): Any = x
def foo: Unit = {
bn({
class A
def foo(x: A): Unit = {}
foo(new A)
})
}
}