diff options
author | Martin Odersky <odersky@gmail.com> | 2013-11-01 18:26:02 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2013-11-01 18:26:02 +0100 |
commit | f920a3186427e9df2fbac97197f2f11331ef4ef3 (patch) | |
tree | 62ab9a95f08650901c91a6ae82361886d67b63a4 /src/dotty | |
parent | 1c17a0f83639ddc4b0fd3ffd294a6a97c887aae3 (diff) | |
download | dotty-f920a3186427e9df2fbac97197f2f11331ef4ef3.tar.gz dotty-f920a3186427e9df2fbac97197f2f11331ef4ef3.tar.bz2 dotty-f920a3186427e9df2fbac97197f2f11331ef4ef3.zip |
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?
Diffstat (limited to 'src/dotty')
-rw-r--r-- | src/dotty/tools/dotc/core/Denotations.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Scopes.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 16 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ImportInfo.scala | 2 |
5 files changed, 19 insertions, 13 deletions
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 = { diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index e2e40e7e2..1d564caee 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -815,8 +815,8 @@ trait Applications extends Compatibility { self: Typer => case defn.FunctionType(args, resultType) => narrowByTypes(alts, args, resultType) - case tp => - alts filter (alt => testCompatible(normalize(alt), tp)) + case pt => + alts filter (alt => testCompatible(normalize(alt), pt)) } if (isDetermined(candidates)) candidates diff --git a/src/dotty/tools/dotc/typer/ImportInfo.scala b/src/dotty/tools/dotc/typer/ImportInfo.scala index 7be914f8b..a87dec069 100644 --- a/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -86,7 +86,7 @@ class ImportInfo(val sym: Symbol, val selectors: List[untpd.Tree], val rootImpor for { renamed <- reverseMapping.keys denot <- pre.member(reverseMapping(renamed)).altsWith(_ is Implicit) - } yield TermRef.withSym(pre, renamed, denot.symbol.asTerm).withDenot(denot) + } yield TermRef.withSig(pre, renamed, denot.signature).withDenot(denot) } override def toString = { |