Skip to content
Closed
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
22 changes: 11 additions & 11 deletions src/dotty/tools/dotc/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object TypeErasure {
case JavaArrayType(elem) =>
isErasedType(elem)
case AnnotatedType(_, tp) =>
isErasedType(tp)
false
case ThisType(tref) =>
isErasedType(tref)
case tp: MethodType =>
Expand Down Expand Up @@ -105,7 +105,7 @@ object TypeErasure {
/** The erasure of a top-level reference. Differs from normal erasure in that
* TermRefs are kept instead of being widened away.
*/
def erasedRef(tp: Type)(implicit ctx: Context): Type = tp match {
def erasedRef(tp: Type)(implicit ctx: Context): Type = tp.stripAnnots match {
case tp: TermRef =>
assert(tp.symbol.exists, tp)
val tp1 = ctx.makePackageObjPrefixExplicit(tp)
Expand Down Expand Up @@ -160,7 +160,7 @@ object TypeErasure {
* as upper bound and that is not Java defined? Arrays of such types are
* erased to `Object` instead of `ObjectArray`.
*/
def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp.dealias match {
def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp.dealias.stripAnnots match {
case tp: TypeRef =>
!tp.symbol.isClass &&
!tp.derivesFrom(defn.ObjectClass) &&
Expand All @@ -186,14 +186,14 @@ object TypeErasure {
* come after S.
* (the reason to pick last is that we prefer classes over traits that way).
*/
def erasedLub(tp1: Type, tp2: Type)(implicit ctx: Context): Type = tp1 match {
def erasedLub(tp1: Type, tp2: Type)(implicit ctx: Context): Type = tp1.stripAnnots match {
case JavaArrayType(elem1) =>
tp2 match {
tp2.stripAnnots match {
case JavaArrayType(elem2) => JavaArrayType(erasedLub(elem1, elem2))
case _ => defn.ObjectType
}
case _ =>
tp2 match {
tp2.stripAnnots match {
case JavaArrayType(_) => defn.ObjectType
case _ =>
val cls2 = tp2.classSymbol
Expand All @@ -216,14 +216,14 @@ object TypeErasure {
* - subtypes over supertypes, unless isJava is set
* - real classes over traits
*/
def erasedGlb(tp1: Type, tp2: Type, isJava: Boolean)(implicit ctx: Context): Type = tp1 match {
def erasedGlb(tp1: Type, tp2: Type, isJava: Boolean)(implicit ctx: Context): Type = tp1.stripAnnots match {
case JavaArrayType(elem1) =>
tp2 match {
tp2.stripAnnots match {
case JavaArrayType(elem2) => JavaArrayType(erasedGlb(elem1, elem2, isJava))
case _ => tp1
}
case _ =>
tp2 match {
tp2.stripAnnots match {
case JavaArrayType(_) => tp2
case _ =>
val tsym1 = tp1.typeSymbol
Expand Down Expand Up @@ -346,7 +346,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
else JavaArrayType(this(elemtp))
}

def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context) = tp match {
def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context) = tp.stripAnnots match {
case ExprType(rt) =>
if (sym is Param) apply(tp)
// Note that params with ExprTypes are eliminated by ElimByName,
Expand All @@ -365,7 +365,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
(if (cls.owner is Package) normalizeClass(cls) else cls).typeRef
}

private def eraseResult(tp: Type)(implicit ctx: Context): Type = tp match {
private def eraseResult(tp: Type)(implicit ctx: Context): Type = tp.stripAnnots match {
case tp: TypeRef =>
val sym = tp.typeSymbol
if (sym eq defn.UnitClass) sym.typeRef
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
/** Is symbol potentially a getter of a mutable variable?
*/
def mayBeVarGetter(sym: Symbol)(implicit ctx: Context): Boolean = {
def maybeGetterType(tpe: Type): Boolean = tpe match {
def maybeGetterType(tpe: Type): Boolean = tpe.stripAnnots match {
case _: ExprType | _: ImplicitMethodType => true
case tpe: PolyType => maybeGetterType(tpe.resultType)
case _ => false
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final class TreeTypeMap(
case tree1 =>
tree1.withType(mapType(tree1.tpe)) match {
case id: Ident if tpd.needsSelect(id.tpe) =>
ref(id.tpe.asInstanceOf[TermRef]).withPos(id.pos)
ref(id.tpe.stripAnnots.asInstanceOf[TermRef]).withPos(id.pos)
case ddef @ DefDef(name, tparams, vparamss, tpt, rhs) =>
val (tmap1, tparams1) = transformDefs(ddef.tparams)
val (tmap2, vparamss1) = tmap1.transformVParamss(vparamss)
Expand Down
20 changes: 14 additions & 6 deletions src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
polyDefDef(sym, Function.const(rhsFn))

def polyDefDef(sym: TermSymbol, rhsFn: List[Type] => List[List[Tree]] => Tree)(implicit ctx: Context): DefDef = {
val (tparams, mtp) = sym.info match {
val (tparams, mtp) = sym.info.stripAnnots match {
case tp: PolyType =>
val tparams = ctx.newTypeParams(sym, tp.paramNames, EmptyFlags, tp.instantiateBounds)
(tparams, tp.instantiate(tparams map (_.typeRef)))
case tp => (Nil, tp)
}

def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match {
def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp.stripAnnots match {
case tp @ MethodType(paramNames, paramTypes) =>
def valueParam(name: TermName, info: Type): TermSymbol =
ctx.newSymbol(sym, name, TermParam, info)
Expand Down Expand Up @@ -256,7 +256,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
// ------ Making references ------------------------------------------------------

def prefixIsElidable(tp: NamedType)(implicit ctx: Context) = {
def test(implicit ctx: Context) = tp.prefix match {
def test(implicit ctx: Context) = tp.prefix.stripAnnots match {
case NoPrefix =>
true
case pre: ThisType =>
Expand All @@ -273,7 +273,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
}

def needsSelect(tp: Type)(implicit ctx: Context) = tp match {
def needsSelect(tp: Type)(implicit ctx: Context) = tp.stripAnnots match {
case tp: TermRef => !prefixIsElidable(tp)
case _ => false
}
Expand All @@ -282,15 +282,15 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def ref(tp: NamedType)(implicit ctx: Context): Tree =
if (tp.isType) TypeTree(tp)
else if (prefixIsElidable(tp)) Ident(tp)
else tp.prefix match {
else tp.prefix.stripAnnots match {
case pre: SingletonType => singleton(pre).select(tp)
case pre => SelectFromTypeTree(TypeTree(pre), tp)
} // no checks necessary

def ref(sym: Symbol)(implicit ctx: Context): Tree =
ref(NamedType(sym.owner.thisType, sym.name, sym.denot))

def singleton(tp: Type)(implicit ctx: Context): Tree = tp match {
def singleton(tp: Type)(implicit ctx: Context): Tree = tp.stripAnnots match {
case tp: TermRef => ref(tp)
case tp: ThisType => This(tp.cls)
case SuperType(qual, _) => singleton(qual)
Expand Down Expand Up @@ -759,6 +759,14 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Ident(defn.ScalaRuntimeModule.requiredMethod(name).termRef).appliedToArgs(args)
}

/** An extractor that pulls out type arguments */
object MaybePoly {
def unapply(tree: Tree): Option[(Tree, List[Tree])] = tree match {
case TypeApply(tree, targs) => Some(tree, targs)
case _ => Some(tree, Nil)
}
}

/** A traverser that passes the enlcosing class or method as an argumenr
* to the traverse method.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ object Denotations {

final def signature(implicit ctx: Context): Signature = {
if (isType) Signature.NotAMethod // don't force info if this is a type SymDenotation
else info match {
else info.stripAnnots match {
case info: MethodicType =>
try info.signature
catch { // !!! DEBUG
Expand Down
9 changes: 5 additions & 4 deletions src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ object SymDenotations {
/** Is `pre` the same as C.thisThis, where C is exactly the owner of this symbol,
* or, if this symbol is protected, a subclass of the owner?
*/
def isCorrectThisType(pre: Type): Boolean = pre match {
def isCorrectThisType(pre: Type): Boolean = pre.stripAnnots match {
case pre: ThisType =>
(pre.cls eq owner) || (this is Protected) && pre.cls.derivesFrom(owner)
case pre: TermRef =>
Expand Down Expand Up @@ -573,7 +573,7 @@ object SymDenotations {
!( this.isTerm
|| this.isStaticOwner
|| ctx.erasedTypes
|| (pre eq NoPrefix) || (pre eq thisType)
|| (pre.stripAnnots eq NoPrefix) || (pre.stripAnnots eq thisType.stripAnnots)
)

/** Is this symbol concrete, or that symbol deferred? */
Expand Down Expand Up @@ -617,7 +617,7 @@ object SymDenotations {
/** The class implementing this module, NoSymbol if not applicable. */
final def moduleClass(implicit ctx: Context): Symbol =
if (this is ModuleVal)
myInfo match {
myInfo.stripAnnots match {
case info: TypeRef => info.symbol
case ExprType(info: TypeRef) => info.symbol // needed after uncurry, when module terms might be accessor defs
case info: LazyType => info.moduleClass
Expand All @@ -626,7 +626,7 @@ object SymDenotations {
else NoSymbol

/** The module implemented by this module class, NoSymbol if not applicable. */
final def sourceModule(implicit ctx: Context): Symbol = myInfo match {
final def sourceModule(implicit ctx: Context): Symbol = myInfo.stripAnnots match {
case ClassInfo(_, _, _, _, selfType: TermRef) if this is ModuleClass =>
selfType.symbol
case info: LazyType =>
Expand Down Expand Up @@ -1363,6 +1363,7 @@ object SymDenotations {
case tp: TypeVar => tp.inst.exists && inCache(tp.inst)
case tp: TypeProxy => inCache(tp.underlying)
case tp: AndOrType => inCache(tp.tp1) && inCache(tp.tp2)
case tp: AnnotatedType => isCachable(tp.tpe)
case _ => true
}

Expand Down
18 changes: 9 additions & 9 deletions src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ class TypeApplications(val self: Type) extends AnyVal {
*/
final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = ctx.traceIndented(s"btwa ${self.show} wrt $base", core, show = true) {
def default = self.baseTypeRef(base).appliedTo(baseArgInfos(base))
self match {
self.stripAnnots match {
case tp: TypeRef =>
tp.info match {
tp.info.stripAnnots match {
case TypeBounds(_, hi) => hi.baseTypeWithArgs(base)
case _ => default
}
Expand Down Expand Up @@ -285,7 +285,7 @@ class TypeApplications(val self: Type) extends AnyVal {
*/
def underlyingIfRepeated(isJava: Boolean)(implicit ctx: Context): Type =
if (self.isRepeatedParam) {
val seqClass = if(isJava) defn.ArrayClass else defn.SeqClass
val seqClass = if (isJava) defn.ArrayClass else defn.SeqClass
translateParameterized(defn.RepeatedParamClass, seqClass)
}
else self
Expand All @@ -297,7 +297,7 @@ class TypeApplications(val self: Type) extends AnyVal {
*/
final def argInfos(interpolate: Boolean)(implicit ctx: Context): List[Type] = {
var tparams: List[TypeSymbol] = null
def recur(tp: Type, refineCount: Int): mutable.ListBuffer[Type] = tp.stripTypeVar match {
def recur(tp: Type, refineCount: Int): mutable.ListBuffer[Type] = tp.stripTypeVar.stripAnnots match {
case tp @ RefinedType(tycon, name) =>
val buf = recur(tycon, refineCount + 1)
if (buf == null) null
Expand Down Expand Up @@ -352,7 +352,7 @@ class TypeApplications(val self: Type) extends AnyVal {
*
* for a contravariant type-parameter becomes L.
*/
final def argInfo(tparam: Symbol, interpolate: Boolean = true)(implicit ctx: Context): Type = self match {
final def argInfo(tparam: Symbol, interpolate: Boolean = true)(implicit ctx: Context): Type = self.stripAnnots match {
case self: TypeAlias => self.alias
case TypeBounds(lo, hi) =>
if (interpolate) {
Expand All @@ -367,14 +367,14 @@ class TypeApplications(val self: Type) extends AnyVal {
}

/** The element type of a sequence or array */
def elemType(implicit ctx: Context): Type = self match {
def elemType(implicit ctx: Context): Type = self.stripAnnots match {
case defn.ArrayType(elemtp) => elemtp
case JavaArrayType(elemtp) => elemtp
case _ => firstBaseArgInfo(defn.SeqClass)
}

def containsSkolemType(target: Type)(implicit ctx: Context): Boolean = {
def recur(tp: Type): Boolean = tp.stripTypeVar match {
def recur(tp: Type): Boolean = tp.stripTypeVar.stripAnnots match {
case SkolemType(tp) =>
tp eq target
case tp: NamedType =>
Expand Down Expand Up @@ -434,7 +434,7 @@ class TypeApplications(val self: Type) extends AnyVal {
for (sym <- boundSyms)
yield TypeRef(SkolemType(rt), correspondingParamName(sym))

def rewrite(tp: Type): Type = tp match {
def rewrite(tp: Type): Type = tp.stripAnnots match {
case tp @ RefinedType(parent, name: TypeName) =>
if (correspondingNames contains name) rewrite(parent)
else RefinedType(
Expand Down Expand Up @@ -482,7 +482,7 @@ class TypeApplications(val self: Type) extends AnyVal {
//println(i"lambda abstract $self wrt $boundSyms%, % --> $res")
res
}
self match {
self.stripAnnots match {
case self @ TypeBounds(lo, hi) =>
self.derivedTypeBounds(lo, expand(TypeBounds.upper(hi)))
case _ =>
Expand Down
Loading