From c79c6644d5739c3376e5eec0a22649360cb9b1b4 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Fri, 15 Mar 2024 12:29:10 +0100 Subject: [PATCH 1/3] Add regression tests --- tests/neg/i19949.scala | 9 +++++++++ tests/pos/i19950.scala | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/neg/i19949.scala create mode 100644 tests/pos/i19950.scala diff --git a/tests/neg/i19949.scala b/tests/neg/i19949.scala new file mode 100644 index 000000000000..96a22e42e079 --- /dev/null +++ b/tests/neg/i19949.scala @@ -0,0 +1,9 @@ + +trait T[N]: + type M = N match + case 0 => Any + +val t: T[Double] = new T[Double] {} +val x: t.M = "hello" // error + +val z: T[Double]#M = "hello" // error diff --git a/tests/pos/i19950.scala b/tests/pos/i19950.scala new file mode 100644 index 000000000000..349140f43ff5 --- /dev/null +++ b/tests/pos/i19950.scala @@ -0,0 +1,10 @@ + +trait Apply[F[_]]: + extension [T <: NonEmptyTuple](tuple: T)(using toMap: Tuple.IsMappedBy[F][T]) + def mapN[B](f: Tuple.InverseMap[T, F] => B): F[B] = ??? + +given Apply[Option] = ??? +given Apply[List] = ??? +given Apply[util.Try] = ??? + +@main def Repro = (Option(1), Option(2), Option(3)).mapN(_ + _ + _) \ No newline at end of file From bd1763d77edee9b53a6bc5af848f0ab0ed7599ff Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Sat, 16 Mar 2024 16:30:28 +0100 Subject: [PATCH 2/3] Account for match types reducing to `ErrorType`s in TypeComparer A match type has no matching cases is reduced to an `ErrorType` (different from throwing a TypeError), in distinction to the other cases for failed match type reduction which return `NoType`. Producing to an ErrorType is usually accompanied by reporting an error, but does appear to be the case when attempting normalization from within the TypeComparer. --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 302ad7987889..b15a9cdb2444 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -543,7 +543,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling recur(tp1.parent, tp2) case tp1: MatchType => val reduced = tp1.reduced - if reduced.exists then + if reduced.exists && !reduced.isError then recur(reduced, tp2) && recordGadtUsageIf { MatchType.thatReducesUsingGadt(tp1) } else thirdTry case _: FlexType => @@ -786,7 +786,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling either(recur(tp1, tp21), recur(tp1, tp22)) || fourthTry case tp2: MatchType => val reduced = tp2.reduced - if reduced.exists then + if reduced.exists && !reduced.isError then recur(tp1, reduced) && recordGadtUsageIf { MatchType.thatReducesUsingGadt(tp2) } else fourthTry From fa3c735171224c249c76c9a7469d5333a12bbca0 Mon Sep 17 00:00:00 2001 From: Eugene Flesselle Date: Sat, 16 Mar 2024 17:38:49 +0100 Subject: [PATCH 3/3] Remove i18211.scala Prior to the changes contained, subtyping trace contained: ``` <== isSubType scala.compiletime.ops.int.S[a] (this error can be ignored for now with `-source:3.3`)> <:< Nothing = true <== isSubType IndexOf[String, Tuple.Drop[(String, Int, String, Boolean), scala.compiletime.ops.int.S[IndexOf[String, (String, Int, String, Boolean)]] ] ] <:< Nothing = true ``` --- tests/pos/i18211.scala | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 tests/pos/i18211.scala diff --git a/tests/pos/i18211.scala b/tests/pos/i18211.scala deleted file mode 100644 index c5ec30ba5d61..000000000000 --- a/tests/pos/i18211.scala +++ /dev/null @@ -1,39 +0,0 @@ -import scala.compiletime.ops.int.* - -type AnyInt[A <: Int] <: Int = A match { - case _ => A -} - -type IndexOf[A, T <: Tuple] <: Int = T match { - case EmptyTuple => -1 - case A *: t => 0 - case _ *: t => - IndexOf[A, t] match { - case -1 => -1 - case AnyInt[a] => S[a] - } -} - -type Indexes[A, T <: Tuple] -object Indexes { - given of[A, T <: Tuple](using IndexOf[A, T] >= 0 =:= true)(using - index: ValueOf[IndexOf[A, T]], - next: Indexes[A, Tuple.Drop[T, S[IndexOf[A, T]]]] - ): Indexes[A, T] = ??? - - given empty[A, T <: Tuple](using IndexOf[A, T] =:= -1): Indexes[A, T] = ??? -} - -class GetAll[A]: - def apply[T <: Tuple](t: T)(using indexes: Indexes[A, T]): List[A] = ??? - -def getAll[A]: GetAll[A] = new GetAll[A] - -def test = - // the code here is trying to get all values from a tuple that has type [X] as a list - - // this works if there are only two strings in the tuple - getAll[String](("str1", 1, "str2", false)) - - //but this not compiles if there are more than two strings in the tuple - getAll[String](("str1", 1, "str2", false, "str3"))