Skip to content

Add missing case to TypeComparer #3713

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

Merged
merged 4 commits into from
Dec 30, 2017
Merged
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ object desugar {
AppliedTypeTree(ref(seqType), t),
New(ref(defn.RepeatedAnnotType), Nil :: Nil))
} else {
assert(ctx.mode.isExpr || ctx.reporter.hasErrors, ctx.mode)
assert(ctx.mode.isExpr || ctx.reporter.hasErrors || ctx.mode.is(Mode.Interactive), ctx.mode)
Copy link
Member

Choose a reason for hiding this comment

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

Any idea why we manage to hit this assertion in the IDE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea, I am afraid.

Select(t, op.name)
}
case PrefixOp(op, t) =>
Expand Down
17 changes: 11 additions & 6 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
isSubType(tp1.resType, tp2.resType.subst(tp2, tp1))
finally comparedTypeLambdas = saved
case _ =>
if (!tp1.isHK) {
tp2 match {
case EtaExpansion(tycon2) if tycon2.symbol.isClass =>
return isSubType(tp1, tycon2)
case _ =>
}
if (tp1.isHK) {
val tparams1 = tp1.typeParams
return isSubType(
HKTypeLambda.fromParams(tparams1, tp1.appliedTo(tparams1.map(_.paramRef))),
Copy link
Member

Choose a reason for hiding this comment

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

Can be written EtaExpansion(tp1) I think.

Copy link
Contributor Author

@odersky odersky Dec 30, 2017

Choose a reason for hiding this comment

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

EtaExpansion only works for class type constructors. I tried to change that, but it would be quite involved, so I thought it was simpler to write the code directly here.

tp2
)
}
else tp2 match {
case EtaExpansion(tycon2) if tycon2.symbol.isClass =>
return isSubType(tp1, tycon2)
case _ =>
}
fourthTry(tp1, tp2)
}
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i2989.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Foo[+X[_]] {
// OK
def foo1[Y[_]](right: Foo[Y]): Foo[Y] = right
// OK
def foo2[Y[_]](right: Foo[[T] => Y[T]]): Foo[Y] = right
// OK
def foo3[Y[_]](right: Foo[[T] => Y[T]]): Foo[[T] => Y[T]] = right
// Error:
// found: Foo[Y](right)
// required: Foo[Y]
def foo4[Y[_]](right: Foo[Y]): Foo[[T] => Y[T]] = right
}
15 changes: 15 additions & 0 deletions tests/pos/i3658.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
object App {
def main(args: Array[String]): Unit = {
trait ModuleSig {
type F[_]
type Type = F

def subst[F[_[_]]](fa: F[List]): F[Type]
}
val Module: ModuleSig = new ModuleSig {
type F[+A] = List[A]

def subst[FF[_[_]]](fa: FF[List]): FF[Type] = fa
}
}
}