Skip to content

Commit d229e72

Browse files
Revert "Backport "Approximate MatchTypes with lub of case bodies, if non-recursive" to LTS" (#21014)
Reverts #20972
2 parents 110688d + c736c3e commit d229e72

File tree

6 files changed

+9
-58
lines changed

6 files changed

+9
-58
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

+1-9
Original file line numberDiff line numberDiff line change
@@ -2280,15 +2280,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
22802280
report.error(MatchTypeScrutineeCannotBeHigherKinded(sel1Tpe), sel1.srcPos)
22812281
val pt1 = if (bound1.isEmpty) pt else bound1.tpe
22822282
val cases1 = tree.cases.mapconserve(typedTypeCase(_, sel1Tpe, pt1))
2283-
val bound2 = if tree.bound.isEmpty then
2284-
val lub = cases1.foldLeft(defn.NothingType: Type): (acc, case1) =>
2285-
if !acc.exists then NoType
2286-
else if case1.body.tpe.isProvisional then NoType
2287-
else acc | case1.body.tpe
2288-
if lub.exists then TypeTree(lub, inferred = true)
2289-
else bound1
2290-
else bound1
2291-
assignType(cpy.MatchTypeTree(tree)(bound2, sel1, cases1), bound2, sel1, cases1)
2283+
assignType(cpy.MatchTypeTree(tree)(bound1, sel1, cases1), bound1, sel1, cases1)
22922284
}
22932285

22942286
def typedByNameTypeTree(tree: untpd.ByNameTypeTree)(using Context): ByNameTypeTree = tree.result match

tests/pos/13633.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object Sums extends App:
2121

2222
type Reverse[A] = ReverseLoop[A, EmptyTuple]
2323

24-
type PlusTri[A, B, C] <: Tuple = (A, B, C) match
24+
type PlusTri[A, B, C] = (A, B, C) match
2525
case (false, false, false) => (false, false)
2626
case (true, false, false) | (false, true, false) | (false, false, true) => (false, true)
2727
case (true, true, false) | (true, false, true) | (false, true, true) => (true, false)

tests/pos/Tuple.Drop.scala

-7
This file was deleted.

tests/pos/Tuple.Elem.scala

-7
This file was deleted.

tests/pos/i19710.scala

-11
This file was deleted.

tests/run-macros/type-show/Test_2.scala

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
11

22
object Test {
33
import TypeToolbox.*
4-
5-
def assertEql[A](obt: A, exp: A): Unit =
6-
assert(obt == exp, s"\nexpected: $exp\nobtained: $obt")
7-
84
def main(args: Array[String]): Unit = {
95
val x = 5
10-
assertEql(show[x.type], "x.type")
11-
assertEql(show[Nil.type], "scala.Nil.type")
12-
assertEql(show[Int], "scala.Int")
13-
assertEql(show[Int => Int], "scala.Function1[scala.Int, scala.Int]")
14-
assertEql(show[(Int, String)], "scala.Tuple2[scala.Int, scala.Predef.String]")
15-
assertEql(show[[X] =>> X match { case Int => Int }],
6+
assert(show[x.type] == "x.type")
7+
assert(show[Nil.type] == "scala.Nil.type")
8+
assert(show[Int] == "scala.Int")
9+
assert(show[Int => Int] == "scala.Function1[scala.Int, scala.Int]")
10+
assert(show[(Int, String)] == "scala.Tuple2[scala.Int, scala.Predef.String]")
11+
assert(show[[X] =>> X match { case Int => Int }] ==
1612
"""[X >: scala.Nothing <: scala.Any] => X match {
1713
| case scala.Int => scala.Int
1814
|}""".stripMargin)
19-
assertEql(showStructure[[X] =>> X match { case Int => Int }],
20-
"""TypeLambda("""+
21-
"""List(X), """+
22-
"""List(TypeBounds("""+
23-
"""TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), """+
24-
"""TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"))), """+
25-
"""MatchType("""+
26-
"""TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), """+ // match type bound
27-
"""ParamRef(binder, 0), """+
28-
"""List("""+
29-
"""MatchCase("""+
30-
"""TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), """+
31-
"""TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int")))))""")
15+
assert(showStructure[[X] =>> X match { case Int => Int }] == """TypeLambda(List(X), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Nothing"), TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"))), MatchType(TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Any"), ParamRef(binder, 0), List(MatchCase(TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int")))))""")
3216

3317
// TODO: more complex types:
3418
// - implicit function types

0 commit comments

Comments
 (0)