From 32c0135b59fe02a70ed0b1a693251a0028d479c8 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 30 Jun 2016 14:27:43 +0200 Subject: Refactorings of GenericTypes and underlying/upperbound 1. Make genericType a trait instead of a class. 2. Make TypeLambda a type proxy 3. Split underlying in TypeProxy into underlying and superType 4. Cleanups in many other places --- src/dotty/tools/dotc/core/SymDenotations.scala | 6 +- src/dotty/tools/dotc/core/TypeApplications.scala | 9 +- src/dotty/tools/dotc/core/TypeComparer.scala | 13 +- src/dotty/tools/dotc/core/TypeErasure.scala | 2 - src/dotty/tools/dotc/core/TypeOps.scala | 9 +- src/dotty/tools/dotc/core/Types.scala | 195 +++++++++------------ .../tools/dotc/transform/ElimStaticThis.scala | 4 +- .../tools/dotc/transform/SuperAccessors.scala | 6 - src/dotty/tools/dotc/typer/Inferencing.scala | 2 +- 9 files changed, 100 insertions(+), 146 deletions(-) (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index dbde4d6f2..e3cbf6669 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1661,12 +1661,10 @@ object SymDenotations { if (cdenot.superClassBits contains symbol.superId) foldGlb(NoType, tp.parents) else NoType case _ => - baseTypeRefOf(tp.underlying) + baseTypeRefOf(tp.superType) } - case tp: HKApply => - baseTypeRefOf(tp.upperBound) // TODO drop? case tp: TypeProxy => - baseTypeRefOf(tp.underlying) + baseTypeRefOf(tp.superType) case AndType(tp1, tp2) => baseTypeRefOf(tp1) & baseTypeRefOf(tp2) case OrType(tp1, tp2) => diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index a685c11c7..94ca7a3ac 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -275,7 +275,7 @@ class TypeApplications(val self: Type) extends AnyVal { if (params.exists(_.name == self.refinedName)) parent1 else self.derivedRefinedType(parent1, self.refinedName, self.refinedInfo) case self: TypeProxy => - self.underlying.widenToNamedTypeParams(params) + self.superType.widenToNamedTypeParams(params) case self: AndOrType => self.derivedAndOrType( self.tp1.widenToNamedTypeParams(params), self.tp2.widenToNamedTypeParams(params)) @@ -317,7 +317,6 @@ class TypeApplications(val self: Type) extends AnyVal { case self: SingletonType => -1 case self: TypeVar => self.origin.knownHK case self: WildcardType => self.optBounds.knownHK - case self: PolyParam => self.underlying.knownHK case self: TypeProxy => self.underlying.knownHK case NoType | _: LazyType => 0 case _ => -1 @@ -568,7 +567,7 @@ class TypeApplications(val self: Type) extends AnyVal { final def baseArgInfos(base: Symbol)(implicit ctx: Context): List[Type] = if (self derivesFrom base) self match { - case self: HKApply => self.upperBound.baseArgInfos(base) + case self: HKApply => self.superType.baseArgInfos(base) case _ => base.typeParams.map(param => self.member(param.name).info.argInfo) } else @@ -596,7 +595,7 @@ class TypeApplications(val self: Type) extends AnyVal { final def firstBaseArgInfo(base: Symbol)(implicit ctx: Context): Type = base.typeParams match { case param :: _ if self derivesFrom base => self match { - case self: HKApply => self.upperBound.firstBaseArgInfo(base) + case self: HKApply => self.superType.firstBaseArgInfo(base) case _ => self.member(param.name).info.argInfo } case _ => @@ -621,7 +620,7 @@ class TypeApplications(val self: Type) extends AnyVal { case tp: TermRef => tp.underlying.baseTypeWithArgs(base) case tp: HKApply => - tp.upperBound.baseTypeWithArgs(base) + tp.superType.baseTypeWithArgs(base) case AndType(tp1, tp2) => tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base) case OrType(tp1, tp2) => diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index bb9124fda..34fe8629e 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -677,7 +677,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { canConstrain(param1) && canInstantiate || isSubType(bounds(param1).hi.applyIfParameterized(args1), tp2) case tycon1: TypeProxy => - isSubType(tycon1.underlying.bounds.hi.applyIfParameterized(args1), tp2) + isSubType(tycon1.superType.applyIfParameterized(args1), tp2) case _ => false } @@ -1218,20 +1218,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { else original(tp1, tp2.appliedTo(tp2.typeParams.map(_.paramBoundsAsSeenFrom(tp2)))) else if (tparams2.isEmpty) original(tp1.appliedTo(tp1.typeParams.map(_.paramBoundsAsSeenFrom(tp1))), tp2) - else { - val numArgs = tparams1.length - def argRefs(tl: GenericType) = List.range(0, numArgs).map(PolyParam(tl, _)) + else TypeLambda( - paramNames = tpnme.syntheticLambdaParamNames(numArgs), + paramNames = tpnme.syntheticLambdaParamNames(tparams1.length), variances = (tparams1, tparams2).zipped.map((tparam1, tparam2) => (tparam1.paramVariance + tparam2.paramVariance) / 2))( paramBoundsExp = tl => (tparams1, tparams2).zipped.map((tparam1, tparam2) => tl.lifted(tparams1, tparam1.paramBoundsAsSeenFrom(tp1)).bounds & tl.lifted(tparams2, tparam2.paramBoundsAsSeenFrom(tp2)).bounds), resultTypeExp = tl => - original(tl.lifted(tparams1, tp1).appliedTo(argRefs(tl)), - tl.lifted(tparams2, tp2).appliedTo(argRefs(tl)))) - } + original(tl.lifted(tparams1, tp1).appliedTo(tl.paramRefs), + tl.lifted(tparams2, tp2).appliedTo(tl.paramRefs))) } /** Try to distribute `&` inside type, detect and handle conflicts diff --git a/src/dotty/tools/dotc/core/TypeErasure.scala b/src/dotty/tools/dotc/core/TypeErasure.scala index 74d2d193f..2e84102f5 100644 --- a/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/src/dotty/tools/dotc/core/TypeErasure.scala @@ -356,8 +356,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean case rt => tp.derivedMethodType(tp.paramNames, formals, rt) } - case tp: TypeLambda => - this(tp.resultType) case tp: PolyType => this(tp.resultType) match { case rt: MethodType => rt diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala index 3a797cce3..80e0fc6f1 100644 --- a/src/dotty/tools/dotc/core/TypeOps.scala +++ b/src/dotty/tools/dotc/core/TypeOps.scala @@ -194,10 +194,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object. case tp: RefinedType => isClassRef(tp.parent) case _ => false } - def next(tp: TypeProxy) = tp.underlying match { - case TypeBounds(_, hi) => hi - case nx => nx - } + /** If `tp1` and `tp2` are typebounds, try to make one fit into the other * or to make them equal, by instantiating uninstantiated type variables. */ @@ -238,13 +235,13 @@ trait TypeOps { this: Context => // TODO: Make standalone object. case tp1: RecType => tp1.rebind(approximateOr(tp1.parent, tp2)) case tp1: TypeProxy if !isClassRef(tp1) => - approximateUnion(next(tp1) | tp2) + approximateUnion(tp1.superType | tp2) case _ => tp2 match { case tp2: RecType => tp2.rebind(approximateOr(tp1, tp2.parent)) case tp2: TypeProxy if !isClassRef(tp2) => - approximateUnion(tp1 | next(tp2)) + approximateUnion(tp1 | tp2.superType) case _ => val commonBaseClasses = tp.mapReduceOr(_.baseClasses)(intersect) val doms = dominators(commonBaseClasses, Nil) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 6f08971ec..85c8fd623 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -147,11 +147,7 @@ object Types { def loop(tp: Type) = tp match { case tp: TypeRef => val sym = tp.symbol - if (sym.isClass) sym.derivesFrom(cls) else tp.underlying.derivesFrom(cls) - case tp: TypeLambda => - tp.resType.derivesFrom(cls) - case tp: HKApply => - tp.tycon.derivesFrom(cls) + if (sym.isClass) sym.derivesFrom(cls) else tp.superType.derivesFrom(cls) case tp: TypeProxy => tp.underlying.derivesFrom(cls) case tp: AndType => @@ -218,29 +214,6 @@ object Types { /** Is this an alias TypeBounds? */ def isAlias: Boolean = this.isInstanceOf[TypeAlias] - /** Is this type a transitive refinement of the given type? - * This is true if the type consists of 0 or more refinements or other - * non-singleton proxies that lead to the `prefix` type. ClassInfos with - * the same class are counted as equal for this purpose. - */ - def refines(prefix: Type)(implicit ctx: Context): Boolean = { - val prefix1 = prefix.dealias - def loop(tp: Type): Boolean = - (tp eq prefix1) || { - tp match { - case base: ClassInfo => - prefix1 match { - case prefix1: ClassInfo => base.cls eq prefix1.cls - case _ => false - } - case base: SingletonType => false - case base: TypeProxy => loop(base.underlying) - case _ => false - } - } - loop(this) - } - // ----- Higher-order combinators ----------------------------------- /** Returns true if there is a part of this type that satisfies predicate `p`. @@ -300,11 +273,9 @@ object Types { constant.tpe.classSymbol case tp: TypeRef => val sym = tp.symbol - if (sym.isClass) sym else tp.underlying.classSymbol + if (sym.isClass) sym else tp.superType.classSymbol case tp: ClassInfo => tp.cls - case tp: TypeLambda => - tp.resType.classSymbol case tp: SingletonType => NoSymbol case tp: TypeProxy => @@ -332,9 +303,7 @@ object Types { tp.cls :: Nil case tp: TypeRef => val sym = tp.symbol - if (sym.isClass) sym.asClass :: Nil else tp.underlying.classSymbols - case tp: TypeLambda => - tp.resType.classSymbols + if (sym.isClass) sym.asClass :: Nil else tp.superType.classSymbols case tp: TypeProxy => tp.underlying.classSymbols case AndType(l, r) => @@ -464,8 +433,6 @@ object Types { go(tp.underlying) case tp: ClassInfo => tp.cls.findMember(name, pre, excluded) - case tp: TypeLambda => - go(tp.resType) case AndType(l, r) => goAnd(l, r) case OrType(l, r) => @@ -548,12 +515,10 @@ object Types { def goApply(tp: HKApply) = tp.tycon match { case tl: TypeLambda => - val res = - go(tl.resType).mapInfo(info => - tl.derivedTypeLambda(tl.paramNames, tl.paramBounds, info).appliedTo(tp.args)) - //println(i"remapping $tp . $name to ${res.info}")// " / ${res.toString}") - res - case _ => go(tp.underlying) + go(tl.resType).mapInfo(info => + tl.derivedTypeLambda(tl.paramNames, tl.paramBounds, info).appliedTo(tp.args)) + case _ => + go(tp.superType) } def goThis(tp: ThisType) = { @@ -878,16 +843,7 @@ object Types { /** Follow aliases and dereferences LazyRefs and instantiated TypeVars until type * is no longer alias type, LazyRef, or instantiated type variable. */ - final def dealias(implicit ctx: Context): Type = strictDealias match { - case tp: LazyRef => tp.ref.dealias - case tp => tp - } - - /** Follow aliases and instantiated TypeVars until type - * is no longer alias type, or instantiated type variable. - * Do not follow LazyRefs - */ - final def strictDealias(implicit ctx: Context): Type = this match { + final def dealias(implicit ctx: Context): Type = this match { case tp: TypeRef => if (tp.symbol.isClass) tp else tp.info match { @@ -899,6 +855,8 @@ object Types { if (tp1.exists) tp1.dealias else tp case tp: AnnotatedType => tp.derivedAnnotatedType(tp.tpe.dealias, tp.annot) + case tp: LazyRef => + tp.ref.dealias case _ => this } @@ -1066,7 +1024,7 @@ object Types { /** The full parent types, including all type arguments */ def parentsWithArgs(implicit ctx: Context): List[Type] = this match { - case tp: TypeProxy => tp.underlying.parentsWithArgs + case tp: TypeProxy => tp.superType.parentsWithArgs case _ => List() } @@ -1080,7 +1038,7 @@ object Types { def givenSelfType(implicit ctx: Context): Type = this match { case tp: RefinedType => tp.wrapIfMember(tp.parent.givenSelfType) case tp: ThisType => tp.tref.givenSelfType - case tp: TypeProxy => tp.underlying.givenSelfType + case tp: TypeProxy => tp.superType.givenSelfType case _ => NoType } @@ -1289,8 +1247,15 @@ object Types { * Each implementation is expected to redefine the `underlying` method. */ abstract class TypeProxy extends Type { + /** The type to which this proxy forwards operations. */ def underlying(implicit ctx: Context): Type + + /** The closest supertype of this type. This is the same as `underlying`, + * except for TypeRefs where the upper bound is returned, and HKApplys, + * where the upper bound of the constructor is re-applied to the arguments. + */ + def superType(implicit ctx: Context): Type = underlying } // Every type has to inherit one of the following four abstract type classes., @@ -1778,10 +1743,11 @@ object Types { type ThisType = TypeRef - override def underlying(implicit ctx: Context): Type = { - val res = info - assert(res != this, this) // TODO drop - res + override def underlying(implicit ctx: Context): Type = info + + override def superType(implicit ctx: Context): Type = info match { + case TypeBounds(_, hi) => hi + case _ => info } } @@ -2107,11 +2073,7 @@ object Types { case _ => false } - override def computeHash = { - assert(parent.exists) - doHash(refinedName, refinedInfo, parent) - } - + override def computeHash = doHash(refinedName, refinedInfo, parent) override def toString = s"RefinedType($parent, $refinedName, $refinedInfo)" } @@ -2161,7 +2123,7 @@ object Types { tp match { case tp: TypeRef => apply(x, tp.prefix) case tp: RecThis => RecType.this eq tp.binder - case tp: LazyRef => true // Assume a reference to be safe. + case tp: LazyRef => true // To be safe, assume a reference exists case _ => foldOver(x, tp) } } @@ -2170,12 +2132,9 @@ object Types { } override def computeHash = doHash(parent) - override def toString = s"RecType($parent | $hashCode)" - private def checkInst(implicit ctx: Context): this.type = { - this - } + private def checkInst(implicit ctx: Context): this.type = this } object RecType { @@ -2521,23 +2480,31 @@ object Types { } } - /** A common superclass of PolyType and TypeLambda */ - abstract class GenericType(val paramNames: List[TypeName])(paramBoundsExp: GenericType => List[TypeBounds], resultTypeExp: GenericType => Type) - extends CachedGroundType with BindingType with TermType { + /** A common supertrait of PolyType and TypeLambda */ + trait GenericType extends BindingType with TermType { - val paramBounds = paramBoundsExp(this) - val resType = resultTypeExp(this) + /** The names of the type parameters */ + val paramNames: List[TypeName] - assert(resType ne null) + /** The bounds of the type parameters */ + val paramBounds: List[TypeBounds] - override def resultType(implicit ctx: Context) = resType + /** The result type of a PolyType / body of a type lambda */ + val resType: Type /** If this is a type lambda, the variances of its parameters, otherwise Nil.*/ - def variances: List[Int] = Nil + def variances: List[Int] + + override def resultType(implicit ctx: Context) = resType + /** Unconditionally create a new generic type like this one with given elements */ + def duplicate(paramNames: List[TypeName] = this.paramNames, paramBounds: List[TypeBounds] = this.paramBounds, resType: Type)(implicit ctx: Context): GenericType + + /** Instantiate result type by substituting parameters with given arguments */ final def instantiate(argTypes: List[Type])(implicit ctx: Context): Type = resultType.substParams(this, argTypes) + /** Instantiate parameter bounds by substituting parameters with given arguments */ def instantiateBounds(argTypes: List[Type])(implicit ctx: Context): List[TypeBounds] = paramBounds.mapConserve(_.substParams(this, argTypes).bounds) @@ -2545,14 +2512,16 @@ object Types { if ((paramNames eq this.paramNames) && (paramBounds eq this.paramBounds) && (resType eq this.resType)) this else duplicate(paramNames, paramBounds, resType) - def duplicate(paramNames: List[TypeName] = this.paramNames, paramBounds: List[TypeBounds] = this.paramBounds, resType: Type)(implicit ctx: Context): GenericType + /** PolyParam references to all type parameters of this type */ + def paramRefs: List[PolyParam] = paramNames.indices.toList.map(PolyParam(this, _)) - def lifted(tparams: List[TypeParamInfo], t: Type)(implicit ctx: Context): Type = + /** The type `[tparams := paramRefs] tp`, where `tparams` can be + * either a list of type parameter symbols or a list of lambda parameters + */ + def lifted(tparams: List[TypeParamInfo], tp: Type)(implicit ctx: Context): Type = tparams match { - case LambdaParam(poly, _) :: _ => - t.subst(poly, this) - case tparams: List[Symbol] => - t.subst(tparams, tparams.indices.toList.map(PolyParam(this, _))) + case LambdaParam(poly, _) :: _ => tp.subst(poly, this) + case tparams: List[Symbol] => tp.subst(tparams, paramRefs) } override def equals(other: Any) = other match { @@ -2563,15 +2532,14 @@ object Types { other.variances == this.variances case _ => false } - - override def computeHash = { - doHash(variances ::: paramNames, resType, paramBounds) - } } /** A type for polymorphic methods */ - class PolyType(paramNames: List[TypeName])(paramBoundsExp: GenericType => List[TypeBounds], resultTypeExp: GenericType => Type) - extends GenericType(paramNames)(paramBoundsExp, resultTypeExp) with MethodOrPoly { + class PolyType(val paramNames: List[TypeName])(paramBoundsExp: GenericType => List[TypeBounds], resultTypeExp: GenericType => Type) + extends CachedGroundType with GenericType with MethodOrPoly { + val paramBounds = paramBoundsExp(this) + val resType = resultTypeExp(this) + def variances = Nil protected def computeSignature(implicit ctx: Context) = resultSignature @@ -2589,6 +2557,8 @@ object Types { x => resType.subst(this, x)) override def toString = s"PolyType($paramNames, $paramBounds, $resType)" + + override def computeHash = doHash(paramNames, resType, paramBounds) } object PolyType { @@ -2606,12 +2576,16 @@ object Types { // ----- HK types: TypeLambda, LambdaParam, HKApply --------------------- /** A type lambda of the form `[v_0 X_0, ..., v_n X_n] => T` */ - class TypeLambda(paramNames: List[TypeName], override val variances: List[Int])(paramBoundsExp: GenericType => List[TypeBounds], resultTypeExp: GenericType => Type) - extends GenericType(paramNames)(paramBoundsExp, resultTypeExp) with ValueType { + class TypeLambda(val paramNames: List[TypeName], val variances: List[Int])(paramBoundsExp: GenericType => List[TypeBounds], resultTypeExp: GenericType => Type) + extends CachedProxyType with GenericType with ValueType { + val paramBounds = paramBoundsExp(this) + val resType = resultTypeExp(this) assert(resType.isInstanceOf[TermType], this) assert(paramNames.nonEmpty) + override def underlying(implicit ctx: Context) = resType + lazy val typeParams: List[LambdaParam] = paramNames.indices.toList.map(new LambdaParam(this, _)) @@ -2631,6 +2605,8 @@ object Types { x => resType.subst(this, x)) override def toString = s"TypeLambda($variances, $paramNames, $paramBounds, $resType)" + + override def computeHash = doHash(variances ::: paramNames, resType, paramBounds) } /** The parameter of a type lambda */ @@ -2663,27 +2639,14 @@ object Types { /** A higher kinded type application `C[T_1, ..., T_n]` */ abstract case class HKApply(tycon: Type, args: List[Type]) extends CachedProxyType with ValueType { - override def underlying(implicit ctx: Context): Type = upperBound - def derivedAppliedType(tycon: Type, args: List[Type])(implicit ctx: Context): Type = - if ((tycon eq this.tycon) && (args eq this.args)) this - else tycon.appliedTo(args) - override def computeHash = doHash(tycon, args) + override def underlying(implicit ctx: Context): Type = tycon - def upperBound(implicit ctx: Context): Type = tycon match { - case tp: TypeRef => - tp.info match { - case TypeBounds(_, hi) => hi.appliedTo(args) - case _ => tp - } - case tp: TypeProxy => tp.underlying.appliedTo(args) + override def superType(implicit ctx: Context): Type = tycon match { + case tp: TypeLambda => defn.AnyType + case tp: TypeProxy => tp.superType.appliedTo(args) case _ => defn.AnyType } - - def typeParams(implicit ctx: Context): List[TypeParamInfo] = { - val tparams = tycon.typeParams - if (tparams.isEmpty) TypeLambda.any(args.length).typeParams else tparams - } /* def lowerBound(implicit ctx: Context): Type = tycon.stripTypeVar match { case tp: TypeRef => @@ -2691,6 +2654,17 @@ object Types { case _ => defn.NothingType } */ + def typeParams(implicit ctx: Context): List[TypeParamInfo] = { + val tparams = tycon.typeParams + if (tparams.isEmpty) TypeLambda.any(args.length).typeParams else tparams + } + + def derivedAppliedType(tycon: Type, args: List[Type])(implicit ctx: Context): Type = + if ((tycon eq this.tycon) && (args eq this.args)) this + else tycon.appliedTo(args) + + override def computeHash = doHash(tycon, args) + protected def checkInst(implicit ctx: Context): this.type = { def check(tycon: Type): Unit = tycon.stripTypeVar match { case tycon: TypeRef if !tycon.symbol.isClass => @@ -2782,7 +2756,7 @@ object Types { override def underlying(implicit ctx: Context): Type = { val bounds = binder.paramBounds - if (bounds == null) NoType // this can happen if the references generic type is not initialized yet + if (bounds == null) NoType // this can happen if the referenced generic type is not initialized yet else bounds(paramNum) } // no customized hashCode/equals needed because cycle is broken in PolyType @@ -3166,8 +3140,7 @@ object Types { override def computeHash = doHash(variance, lo, hi) override def equals(that: Any): Boolean = that match { case that: TypeBounds => - (this.lo eq that.lo) && (this.hi eq that.hi) && - (this.variance == that.variance) + (this.lo eq that.lo) && (this.hi eq that.hi) && (this.variance == that.variance) case _ => false } @@ -3848,8 +3821,6 @@ object Types { class MergeError(msg: String, val tp1: Type, val tp2: Type) extends TypeError(msg) - @sharable val dummyRec = new RecType(rt => NoType) - // ----- Debug --------------------------------------------------------- @sharable var debugTrace = false diff --git a/src/dotty/tools/dotc/transform/ElimStaticThis.scala b/src/dotty/tools/dotc/transform/ElimStaticThis.scala index 3afcfa685..0601e0122 100644 --- a/src/dotty/tools/dotc/transform/ElimStaticThis.scala +++ b/src/dotty/tools/dotc/transform/ElimStaticThis.scala @@ -27,8 +27,8 @@ class ElimStaticThis extends MiniPhaseTransform { override def transformIdent(tree: tpd.Ident)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = { if (ctx.owner.enclosingMethod.is(JavaStatic)) { tree.tpe match { - case TermRef(thiz: ThisType, _) if thiz.underlying.typeSymbol.is(ModuleClass) => - ref(thiz.underlying.typeSymbol.sourceModule).select(tree.symbol) + case TermRef(thiz: ThisType, _) if thiz.cls.is(ModuleClass) => + ref(thiz.cls.sourceModule).select(tree.symbol) case TermRef(thiz: ThisType, _) => assert(tree.symbol.is(Flags.JavaStatic)) tree diff --git a/src/dotty/tools/dotc/transform/SuperAccessors.scala b/src/dotty/tools/dotc/transform/SuperAccessors.scala index ae9c493ae..6af991f27 100644 --- a/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -167,12 +167,6 @@ class SuperAccessors(thisTransformer: DenotTransformer) { val accName = sym.name.protectedAccessorName - def isThisType(tpe: Type): Boolean = tpe match { - case tpe: ThisType => !tpe.cls.is(PackageClass) - case tpe: TypeProxy => isThisType(tpe.underlying) - case _ => false - } - // if the result type depends on the this type of an enclosing class, the accessor // has to take an object of exactly this type, otherwise it's more general val receiverType = diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index 28f3af7cb..e024192c3 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -178,7 +178,7 @@ object Inferencing { case tp: TypeRef if !tp.symbol.isClass => widenForMatchSelector(tp.info.bounds.hi) case tp: HKApply => - widenForMatchSelector(tp.upperBound) + widenForMatchSelector(tp.superType) case tp: AnnotatedType => tp.derivedAnnotatedType(widenForMatchSelector(tp.tpe), tp.annot) case tp => tp -- cgit v1.2.3