Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gadt unification #5611

Merged
merged 8 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 6 additions & 11 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,9 @@ class TypeComparer(initctx: Context) extends 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, followSuperType: Boolean): Boolean =
def compareLower(tycon2bounds: TypeBounds, tyconIsTypeRef: Boolean): Boolean =
if ((tycon2bounds.lo `eq` tycon2bounds.hi) && !tycon2bounds.isInstanceOf[MatchAlias])
if (followSuperType) recur(tp1, tp2.superType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It reverted commit fills a hole in the subtype checker. What tests failed before we reverted it? It would be good to find a root cause for the failure.

Copy link
Contributor Author

@abgruszecki abgruszecki Dec 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeSafeLambda failed. Since this PR anyway leaves GADTs using HKTs unsound, I wanted to focus first on solving #5630, and then to come back to this problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, agreed. Maybe make an issue so that it is not forgotten?

if (tyconIsTypeRef) recur(tp1, tp2.superType)
else isSubApproxHi(tp1, tycon2bounds.lo.applyIfParameterized(args2))
else
fallback(tycon2bounds.lo)
Expand All @@ -841,15 +841,13 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
case param2: TypeParamRef =>
isMatchingApply(tp1) ||
canConstrain(param2) && canInstantiate(param2) ||
compareLower(bounds(param2), followSuperType = false)
compareLower(bounds(param2), tyconIsTypeRef = false)
case tycon2: TypeRef =>
isMatchingApply(tp1) ||
defn.isTypelevel_S(tycon2.symbol) && compareS(tp2, tp1, fromBelow = true) || {
tycon2.info match {
case info2: TypeBounds =>
val gbounds2 = ctx.gadt.bounds(tycon2.symbol)
if (gbounds2 == null) compareLower(info2, followSuperType = true)
else compareLower(gbounds2 & info2, followSuperType = false)
compareLower(info2, tyconIsTypeRef = true)
case info2: ClassInfo =>
tycon2.name.toString.startsWith("Tuple") &&
defn.isTupleType(tp2) && isSubType(tp1, tp2.toNestedPairs) ||
Expand Down Expand Up @@ -885,11 +883,8 @@ class TypeComparer(initctx: Context) extends ConstraintHandling {
case tycon1: TypeRef =>
val sym = tycon1.symbol
!sym.isClass && (
defn.isTypelevel_S(sym) && compareS(tp1, tp2, fromBelow = false) || {
val gbounds1 = ctx.gadt.bounds(tycon1.symbol)
if (gbounds1 == null) recur(tp1.superType, tp2)
else recur((gbounds1.hi & tycon1.info.bounds.hi).applyIfParameterized(args1), tp2)
})
defn.isTypelevel_S(sym) && compareS(tp1, tp2, fromBelow = false) ||
recur(tp1.superType, tp2))
case tycon1: TypeProxy =>
recur(tp1.superType, tp2)
case _ =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ object Types {
case _ =>
go(tp.superType)
}
case tp: ThisType =>
case tp: ThisType => // ??? inline
goThis(tp)
case tp: RefinedType =>
if (name eq tp.refinedName) goRefined(tp) else go(tp.parent)
Expand Down