From f920a3186427e9df2fbac97197f2f11331ef4ef3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 1 Nov 2013 18:26:02 +0100 Subject: Changed handling of signatures in TermRefs. Previously, plain TermRefs had signature NotAMethod. The problem is if the TermRef represents an overloaded term and one of the alternatives is NotAMethod. Then creating the alternative will overwrite (via hash-consing) the overloaded ref. Solution: Introduc new pseudo-signature "UnknownSignature" which is given to plain TermRefs. Also, need to be careful now that all members that denote a specific alternative of a possibly overloaded denotation are referenced by a TermRefWithSig, not a plain TermRef. Previously, implicit members did not follow that, which meant that, what worked, worked only by accident. Still to do: Clean up signatures, termref creation methods. Should TermRef.withDenot automatically set the signature? --- src/dotty/tools/dotc/core/Denotations.scala | 4 +++- src/dotty/tools/dotc/core/Scopes.scala | 6 ++++-- src/dotty/tools/dotc/core/Types.scala | 16 +++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/dotty/tools/dotc/core') diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 045f74300..4ab911160 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -8,7 +8,7 @@ import Names.{Name, PreName} import Names.TypeName import Symbols.NoSymbol import Symbols._ -import Types._, Periods._, Flags._, Transformers._ +import Types._, Periods._, Flags._, Transformers._, Decorators._ import printing.Texts._ import printing.Printer import io.AbstractFile @@ -85,6 +85,8 @@ object Denotations { */ val NotAMethod: Signature = List(Names.EmptyTypeName) + val UnknownSignature: Signature = List(" ".toTypeName) + /** A denotation is the result of resolving * a name (either simple identifier or select) during a given period. * diff --git a/src/dotty/tools/dotc/core/Scopes.scala b/src/dotty/tools/dotc/core/Scopes.scala index bd67801e1..46cbee99d 100644 --- a/src/dotty/tools/dotc/core/Scopes.scala +++ b/src/dotty/tools/dotc/core/Scopes.scala @@ -292,8 +292,10 @@ object Scopes { var irefs = new ListBuffer[TermRef] var e = lastEntry while (e ne null) { - if (e.sym is Implicit) - irefs += TermRef.withSym(NoPrefix, e.sym.asTerm).withDenot(e.sym.denot) + if (e.sym is Implicit) { + val d = e.sym.denot + irefs += TermRef.withSig(NoPrefix, e.sym.asTerm.name, d.signature).withDenot(e.sym.denot) + } e = e.prev } irefs.toList diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index efd8f3594..ba8b4f139 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -528,7 +528,7 @@ object Types { memberNames(implicitFilter).toList .flatMap(name => member(name) .altsWith(_ is Implicit) - .map(d => TermRef.withSym(this, d.symbol.asTerm).withDenot(d))) + .map(d => TermRef.withSig(this, d.symbol.asTerm.name, d.signature).withDenot(d))) } /** The info of `sym`, seen as a member of this type. */ @@ -1383,7 +1383,9 @@ object Types { } abstract case class TermRef(override val prefix: Type, name: TermName) extends NamedType with SingletonType { - protected def sig: Signature = NotAMethod + protected def sig: Signature = UnknownSignature + + override def signature(implicit ctx: Context): Signature = denot.signature def isOverloaded(implicit ctx: Context) = denot.isOverloaded @@ -1440,7 +1442,7 @@ object Types { */ final class TermRefWithSignature(prefix: Type, name: TermName, override val sig: Signature) extends TermRef(prefix, name) { - assert(sig != NotAMethod) + assert(sig != UnknownSignature) override def signature(implicit ctx: Context) = sig override def loadDenot(implicit ctx: Context): Denotation = super.loadDenot.atSignature(sig) @@ -1468,7 +1470,7 @@ object Types { def withSym(prefix: Type, sym: TermSymbol)(implicit ctx: Context): TermRef = withSym(prefix, sym.name, sym) def withSig(prefix: Type, name: TermName, sig: Signature)(implicit ctx: Context): TermRef = - if (sig == NotAMethod) apply(prefix, name) + if (sig == UnknownSignature) apply(prefix, name) else unique(new TermRefWithSignature(prefix, name, sig)) } @@ -1666,15 +1668,15 @@ object Types { myIsDependent } - private[this] var _signature: Signature = _ + private[this] var mySignature: Signature = _ private[this] var signatureRunId: Int = NoRunId override def signature(implicit ctx: Context): Signature = { if (ctx.runId != signatureRunId) { - _signature = computeSignature + mySignature = computeSignature signatureRunId = ctx.runId } - _signature + mySignature } private def computeSignature(implicit ctx: Context): Signature = { -- cgit v1.2.3