From 4fb545aed099f50ce64dfee39bf9138c3ee7cc5c Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 24 Jul 2024 17:58:29 +0200 Subject: [PATCH 1/2] Revert "Approximate MatchTypes with lub of case bodies, if non-recursive" --- compiler/src/dotty/tools/dotc/core/TypeComparer.scala | 7 ------- compiler/src/dotty/tools/dotc/typer/Typer.scala | 10 +--------- tests/pos/13633.scala | 2 +- tests/pos/Tuple.Drop.scala | 7 ------- tests/pos/Tuple.Elem.scala | 7 ------- tests/pos/i19710.scala | 11 ----------- 6 files changed, 2 insertions(+), 42 deletions(-) delete mode 100644 tests/pos/Tuple.Drop.scala delete mode 100644 tests/pos/Tuple.Elem.scala delete mode 100644 tests/pos/i19710.scala diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 140b42e0e9a9..735f6f11dad7 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2915,13 +2915,6 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling tp.tryCompiletimeConstantFold case tp: HKTypeLambda => tp - case tp: ParamRef => - val st = tp.superTypeNormalized - if st.exists then - disjointnessBoundary(st) - else - // workaround for when ParamRef#underlying returns NoType - defn.AnyType case tp: TypeProxy => disjointnessBoundary(tp.superTypeNormalized) case tp: WildcardType => diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index c90de0ae19a1..53a10a64c277 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2604,15 +2604,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer report.error(MatchTypeScrutineeCannotBeHigherKinded(sel1Tpe), sel1.srcPos) val pt1 = if (bound1.isEmpty) pt else bound1.tpe val cases1 = tree.cases.mapconserve(typedTypeCase(_, sel1Tpe, pt1)) - val bound2 = if tree.bound.isEmpty then - val lub = cases1.foldLeft(defn.NothingType: Type): (acc, case1) => - if !acc.exists then NoType - else if case1.body.tpe.isProvisional then NoType - else acc | case1.body.tpe - if lub.exists then TypeTree(lub, inferred = true) - else bound1 - else bound1 - assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1) + assignType(cpy.MatchTypeTree(tree)(bound1, sel1, cases1), bound1, sel1, cases1) } def typedByNameTypeTree(tree: untpd.ByNameTypeTree)(using Context): ByNameTypeTree = tree.result match diff --git a/tests/pos/13633.scala b/tests/pos/13633.scala index 8883ef98d0be..ca0f7e68e81e 100644 --- a/tests/pos/13633.scala +++ b/tests/pos/13633.scala @@ -21,7 +21,7 @@ object Sums extends App: type Reverse[A] = ReverseLoop[A, EmptyTuple] - type PlusTri[A, B, C] <: Tuple = (A, B, C) match + type PlusTri[A, B, C] = (A, B, C) match case (false, false, false) => (false, false) case (true, false, false) | (false, true, false) | (false, false, true) => (false, true) case (true, true, false) | (true, false, true) | (false, true, true) => (true, false) diff --git a/tests/pos/Tuple.Drop.scala b/tests/pos/Tuple.Drop.scala deleted file mode 100644 index 9b88cc227966..000000000000 --- a/tests/pos/Tuple.Drop.scala +++ /dev/null @@ -1,7 +0,0 @@ -import compiletime.ops.int.* - -type Drop[T <: Tuple, N <: Int] <: Tuple = N match - case 0 => T - case S[n1] => T match - case EmptyTuple => EmptyTuple - case x *: xs => Drop[xs, n1] diff --git a/tests/pos/Tuple.Elem.scala b/tests/pos/Tuple.Elem.scala deleted file mode 100644 index 81494485c321..000000000000 --- a/tests/pos/Tuple.Elem.scala +++ /dev/null @@ -1,7 +0,0 @@ -import compiletime.ops.int.* - -type Elem[T <: Tuple, I <: Int] = T match - case h *: tail => - I match - case 0 => h - case S[j] => Elem[tail, j] diff --git a/tests/pos/i19710.scala b/tests/pos/i19710.scala deleted file mode 100644 index 03fd1e2d80b3..000000000000 --- a/tests/pos/i19710.scala +++ /dev/null @@ -1,11 +0,0 @@ -import scala.util.NotGiven - -type HasName1 = [n] =>> [x] =>> x match { - case n => true - case _ => false - } -@main def Test = { - summon[HasName1["foo"]["foo"] =:= true] - summon[NotGiven[HasName1["foo"]["bar"] =:= true]] - summon[Tuple.Filter[(1, "foo", 2, "bar"), HasName1["foo"]] =:= Tuple1["foo"]] // error -} From 8b82e699d051686ce9bec67c5f3ef1e2b18a556e Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Wed, 24 Jul 2024 19:53:08 +0200 Subject: [PATCH 2/2] Fix failing run-macros/type-show test --- tests/run-macros/type-show/Test_2.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-macros/type-show/Test_2.scala b/tests/run-macros/type-show/Test_2.scala index de845f3e84dd..3bc9da043885 100644 --- a/tests/run-macros/type-show/Test_2.scala +++ b/tests/run-macros/type-show/Test_2.scala @@ -23,7 +23,7 @@ object Test { """TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), """+ """TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"))), """+ """MatchType("""+ - """TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "")), "scala"), "Int"), """+ // match type bound + """TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"), """+ // match type bound """ParamRef(binder, 0), """+ """List("""+ """MatchCase("""+