From 5d38be773a2083fa2112f5cb688070b867634120 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 10 Jan 2014 03:41:49 +0100 Subject: Mover termRef/typeRef and friends up to Denotation. Needed for implicit search, because some implicits might be UniqueRefs, not SymDenotations --- src/dotty/tools/dotc/core/Denotations.scala | 30 ++++++++++++++++++++++++++ src/dotty/tools/dotc/core/SymDenotations.scala | 24 ++++----------------- src/dotty/tools/dotc/core/Types.scala | 2 +- 3 files changed, 35 insertions(+), 21 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index f2df71627..e6d5023e5 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -392,6 +392,36 @@ object Denotations { def atSignature(sig: Signature)(implicit ctx: Context): SingleDenotation = if (sig matches signature) this else NoDenotation + // ------ Forming types ------------------------------------------- + + /** The TypeRef representing this type denotation at its original location. */ + def typeRef(implicit ctx: Context): TypeRef = + TypeRef(symbol.owner.thisType, symbol.name.asTypeName, this) + + /** The TermRef representing this term denotation at its original location. */ + def termRef(implicit ctx: Context): TermRef = + TermRef(symbol.owner.thisType, symbol.name.asTermName, this) + + /** The TermRef representing this term denotation at its original location + * and at signature `NotAMethod`. + */ + def valRef(implicit ctx: Context): TermRef = + TermRef.withSig(symbol.owner.thisType, symbol.name.asTermName, Signature.NotAMethod, this) + + /** The TermRef representing this term denotation at its original location + * at the denotation's signature. + * @note Unlike `valRef` and `termRef`, this will force the completion of the + * denotation via a call to `info`. + */ + def termRefWithSig(implicit ctx: Context): TermRef = + TermRef.withSig(symbol.owner.thisType, symbol.name.asTermName, signature, this) + + /** The NamedType representing this denotation at its original location. + * Same as either `typeRef` or `termRefWithSig` depending whether this denotes a type or not. + */ + def namedType(implicit ctx: Context): NamedType = + if (isType) typeRef else termRefWithSig + // ------ Transformations ----------------------------------------- private[this] var myValidFor: Period = Nowhere diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 1904fdbb5..58f148ba5 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -654,34 +654,18 @@ object SymDenotations { /** The type This(cls), where cls is this class, NoPrefix for all other symbols */ def thisType(implicit ctx: Context): Type = NoPrefix - /** The TypeRef representing this type denotation at its original location. */ - def typeRef(implicit ctx: Context): TypeRef = + override def typeRef(implicit ctx: Context): TypeRef = TypeRef(owner.thisType, name.asTypeName, this) - /** The TermRef representing this term denotation at its original location. */ - def termRef(implicit ctx: Context): TermRef = + override def termRef(implicit ctx: Context): TermRef = TermRef(owner.thisType, name.asTermName, this) - /** The TermRef representing this term denotation at its original location - * and at signature `NotAMethod`. - */ - def valRef(implicit ctx: Context): TermRef = + override def valRef(implicit ctx: Context): TermRef = TermRef.withSig(owner.thisType, name.asTermName, Signature.NotAMethod, this) - /** The TermRef representing this term denotation at its original location - * at the denotation's signature. - * @note Unlike `valRef` and `termRef`, this will force the completion of the - * denotation via a call to `info`. - */ - def termRefWithSig(implicit ctx: Context): TermRef = + override def termRefWithSig(implicit ctx: Context): TermRef = TermRef.withSig(owner.thisType, name.asTermName, signature, this) - /** The NamedType representing this denotation at its original location. - * Same as either `typeRef` or `termRefWithSig` depending whether this denotes a type or not. - */ - def namedType(implicit ctx: Context): NamedType = - if (isType) typeRef else termRefWithSig - /** The variance of this type parameter or type member as an Int, with * +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter */ diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index ffc7573b9..e1e3e9c97 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -448,7 +448,7 @@ object Types { final def implicitMembers(implicit ctx: Context): List[TermRef] = track("implicitMembers") { memberDenots(implicitFilter, (name, buf) => buf ++= member(name).altsWith(_ is Implicit)) - .toList.map(_.asInstanceOf[SymDenotation].termRefWithSig) + .toList.map(_.termRefWithSig) } /** The info of `sym`, seen as a member of this type. */ -- cgit v1.2.3