diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2016-07-25 13:58:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-25 13:58:06 -0700 |
commit | 0ba8d7de28333886b88432ba4a9cdf05b222e85a (patch) | |
tree | dc9916c394c32710fc50481d41fb50e217749953 /src | |
parent | b6882d6402bfc290a1fe589425d6dc4ff16976a8 (diff) | |
parent | 006748d895ade64b0b63916996eb7df8258def18 (diff) | |
download | dotty-0ba8d7de28333886b88432ba4a9cdf05b222e85a.tar.gz dotty-0ba8d7de28333886b88432ba4a9cdf05b222e85a.tar.bz2 dotty-0ba8d7de28333886b88432ba4a9cdf05b222e85a.zip |
Merge pull request #1409 from dotty-staging/fix-hk-typdefs-of-lambdas
Fix parameterized typedefs with lambdas as rhs
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/TypeApplications.scala | 7 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 19 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Types.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 12 |
4 files changed, 22 insertions, 17 deletions
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index cb11d3fdc..af362f4da 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -223,12 +223,12 @@ class TypeApplications(val self: Type) extends AnyVal { self.parent.typeParams.filterNot(_.paramName == self.refinedName) case self: RecType => self.parent.typeParams - case _: HKApply | _: SingletonType => + case _: SingletonType => Nil case self: WildcardType => self.optBounds.typeParams case self: TypeProxy => - self.underlying.typeParams + self.superType.typeParams case _ => Nil } @@ -312,14 +312,13 @@ class TypeApplications(val self: Type) extends AnyVal { case self: TypeRef => self.info.isHK case self: RefinedType => false case self: TypeLambda => true - case self: HKApply => false case self: SingletonType => false case self: TypeVar => // Using `origin` instead of `underlying`, as is done for typeParams, // avoids having to set ephemeral in some cases. self.origin.isHK case self: WildcardType => self.optBounds.isHK - case self: TypeProxy => self.underlying.isHK + case self: TypeProxy => self.superType.isHK case _ => false } diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index e984970b4..18eb424bc 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -665,6 +665,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { } } + /** Fall back to comparing either with `fourthTry` or against the lower + * approximation of the rhs. + * @param tyconLo The type constructor's lower approximation. + */ + def fallback(tyconLo: Type) = + either(fourthTry(tp1, tp2), isSubType(tp1, tyconLo.applyIfParameterized(args2))) + /** Let `tycon2bounds` be the bounds of the RHS type constructor `tycon2`. * Let `app2 = tp2` where the type constructor of `tp2` is replaced by * `tycon2bounds.lo`. @@ -674,13 +681,13 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { * tp1 <:< tp2 using fourthTry (this might instantiate params in tp1) * tp1 <:< app2 using isSubType (this might instantiate params in tp2) */ - def compareLower(tycon2bounds: TypeBounds, tyconIsTypeRef: Boolean): Boolean = { - def app2 = tycon2bounds.lo.applyIfParameterized(args2) + def compareLower(tycon2bounds: TypeBounds, tyconIsTypeRef: Boolean): Boolean = if (tycon2bounds.lo eq tycon2bounds.hi) - isSubType(tp1, if (tyconIsTypeRef) tp2.superType else app2) + isSubType(tp1, + if (tyconIsTypeRef) tp2.superType + else tycon2bounds.lo.applyIfParameterized(args2)) else - either(fourthTry(tp1, tp2), isSubType(tp1, app2)) - } + fallback(tycon2bounds.lo) tycon2 match { case param2: PolyParam => @@ -693,6 +700,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { compareLower(tycon2.info.bounds, tyconIsTypeRef = true) case _: TypeVar | _: AnnotatedType => isSubType(tp1, tp2.superType) + case tycon2: HKApply => + fallback(tycon2.lowerBound) case _ => false } diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 373428108..7211c0a9b 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -2653,7 +2653,6 @@ object Types { cachedSuper } - /* (Not needed yet) */ def lowerBound(implicit ctx: Context) = tycon.stripTypeVar match { case tycon: TypeRef => tycon.info match { diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 26c8f5c95..d1074364c 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -936,13 +936,8 @@ class Namer { typer: Typer => } def typeDefSig(tdef: TypeDef, sym: Symbol, tparamSyms: List[TypeSymbol])(implicit ctx: Context): Type = { - val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree] - //val toParameterize = tparamSyms.nonEmpty && !isDerived - //val needsLambda = sym.allOverriddenSymbols.exists(_ is HigherKinded) && !isDerived def abstracted(tp: Type): Type = - if (tparamSyms.nonEmpty && !tp.isHK) tp.LambdaAbstract(tparamSyms) - //else if (toParameterize) tp.parameterizeWith(tparamSyms) - else tp + if (tparamSyms.nonEmpty) tp.LambdaAbstract(tparamSyms) else tp val dummyInfo = abstracted(TypeBounds.empty) sym.info = dummyInfo @@ -956,7 +951,10 @@ class Namer { typer: Typer => // // The scheme critically relies on an implementation detail of isRef, which // inspects a TypeRef's info, instead of simply dealiasing alias types. - val rhsType = abstracted(typedAheadType(tdef.rhs).tpe) + + val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree] + val rhsBodyType = typedAheadType(tdef.rhs).tpe + val rhsType = if (isDerived) rhsBodyType else abstracted(rhsBodyType) val unsafeInfo = rhsType match { case bounds: TypeBounds => bounds case alias => TypeAlias(alias, if (sym is Local) sym.variance else 0) |