From c00f2146504ff1c15b15230f067d09750de1a618 Mon Sep 17 00:00:00 2001 From: Joel Wilsson Date: Fri, 30 Aug 2024 16:02:39 +0200 Subject: [PATCH 1/2] Handle NoType in TypeComparer.disjointnessBoundary Closes #20265 --- .../dotty/tools/dotc/core/TypeComparer.scala | 2 ++ tests/neg/i20265.check | 28 +++++++++++++++++++ tests/neg/i20265.scala | 23 +++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 tests/neg/i20265.check create mode 100644 tests/neg/i20265.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 0abd92ee784d..6d21143a71ed 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -3070,6 +3070,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling disjointnessBoundary(tp.effectiveBounds.hi) case tp: ErrorType => defn.AnyType + case tp: NoType.type => + defn.AnyType end disjointnessBoundary (disjointnessBoundary(tp1), disjointnessBoundary(tp2)) match diff --git a/tests/neg/i20265.check b/tests/neg/i20265.check new file mode 100644 index 000000000000..607c2c2fde45 --- /dev/null +++ b/tests/neg/i20265.check @@ -0,0 +1,28 @@ +-- [E172] Type Error: tests/neg/i20265.scala:22:95 --------------------------------------------------------------------- +22 | println(summon[((String --> Unit) * (String --> Unit)) =:= Hinze[(String + String) --> Unit]]) // error + | ^ + | Cannot prove that (String --> Unit) * (String --> Unit) =:= Hinze[String + String --> Unit]. + | + | Note: a match type could not be fully reduced: + | + | trying to reduce Hinze[String + String --> Unit] + | failed since selector (String + String --> Unit)#unfix + | does not match case k1 + k2 --> v => Hinze[k1 --> v] * Hinze[k2 --> v] + | and cannot be shown to be disjoint from it either. + | Therefore, reduction cannot advance to the remaining case + | + | case k1 * k2 --> v => k1 --> Hinze[k2 --> v] +-- [E172] Type Error: tests/neg/i20265.scala:23:66 --------------------------------------------------------------------- +23 | println(summon[String =:= Hinze[Fix[Lambda[String]#L] --> Unit]]) // error + | ^ + | Cannot prove that String =:= Hinze[Fix[[X] =>> String + String * X + X * X] --> Unit]. + | + | Note: a match type could not be fully reduced: + | + | trying to reduce Hinze[Fix[[X] =>> String + String * X + X * X] --> Unit] + | failed since selector (Fix[[X] =>> String + String * X + X * X] --> Unit)#unfix + | does not match case k1 + k2 --> v => Hinze[k1 --> v] * Hinze[k2 --> v] + | and cannot be shown to be disjoint from it either. + | Therefore, reduction cannot advance to the remaining case + | + | case k1 * k2 --> v => k1 --> Hinze[k2 --> v] diff --git a/tests/neg/i20265.scala b/tests/neg/i20265.scala new file mode 100644 index 000000000000..1d312188ae99 --- /dev/null +++ b/tests/neg/i20265.scala @@ -0,0 +1,23 @@ +//> using options -source:3.3 + +trait Poly +trait -->[X, Y] extends Poly +trait +[X, Y] extends Poly +trait *[X, Y] extends Poly + +type Hinze[X <: Fix[?]] = X#unfix match + case (k1 + k2) --> v => Hinze[(k1 --> v)] * Hinze[(k2 --> v)] + case (k1 * k2) --> v => k1 --> Hinze[(k2 --> v)] + +trait Lambda[V]: + type Abs[X] = V * X + type App[X] = X * X + type L[X] = V + Abs[X] + App[X] + +trait Fix[F[X]]: + type unfix = F[Fix[F]] + +@main +def m = + println(summon[((String --> Unit) * (String --> Unit)) =:= Hinze[(String + String) --> Unit]]) // error + println(summon[String =:= Hinze[Fix[Lambda[String]#L] --> Unit]]) // error From 3d8a70fe81381b873236529401f6a0740c12bf41 Mon Sep 17 00:00:00 2001 From: Joel Wilsson Date: Sun, 26 Jan 2025 17:51:29 +0100 Subject: [PATCH 2/2] Add test that crashes without -source 3.3 --- tests/neg/i20265-1.check | 5 +++++ tests/neg/i20265-1.scala | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/neg/i20265-1.check create mode 100644 tests/neg/i20265-1.scala diff --git a/tests/neg/i20265-1.check b/tests/neg/i20265-1.check new file mode 100644 index 000000000000..6eb9f4cfe5c6 --- /dev/null +++ b/tests/neg/i20265-1.check @@ -0,0 +1,5 @@ +-- Error: tests/neg/i20265-1.scala:4:6 --------------------------------------------------------------------------------- +4 | def apply(args: Tuple.Map[m.MirroredElemTypes, Expr]): Expr[T] = ??? // error + | ^ + | non-private method apply in trait Ops refers to private given instance m + | in its type signature (args: Tuple.Map[Ops.this.m.MirroredElemTypes, Expr]): Expr[T] diff --git a/tests/neg/i20265-1.scala b/tests/neg/i20265-1.scala new file mode 100644 index 000000000000..085d387ae901 --- /dev/null +++ b/tests/neg/i20265-1.scala @@ -0,0 +1,9 @@ +trait Expr[T] + +trait Ops[T](using m: scala.deriving.Mirror.ProductOf[T]) { + def apply(args: Tuple.Map[m.MirroredElemTypes, Expr]): Expr[T] = ??? // error +} + +case class P(a: Int) +object P extends Ops[P] +