Skip to content

Revert "Backport "Approximate MatchTypes with lub of case bodies, if non-recursive" to LTS" #21014

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 1 commit into from
Jul 5, 2024
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
10 changes: 1 addition & 9 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2280,15 +2280,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
Expand Down
2 changes: 1 addition & 1 deletion tests/pos/13633.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions tests/pos/Tuple.Drop.scala

This file was deleted.

7 changes: 0 additions & 7 deletions tests/pos/Tuple.Elem.scala

This file was deleted.

11 changes: 0 additions & 11 deletions tests/pos/i19710.scala

This file was deleted.

30 changes: 7 additions & 23 deletions tests/run-macros/type-show/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@

object Test {
import TypeToolbox.*

def assertEql[A](obt: A, exp: A): Unit =
assert(obt == exp, s"\nexpected: $exp\nobtained: $obt")

def main(args: Array[String]): Unit = {
val x = 5
assertEql(show[x.type], "x.type")
assertEql(show[Nil.type], "scala.Nil.type")
assertEql(show[Int], "scala.Int")
assertEql(show[Int => Int], "scala.Function1[scala.Int, scala.Int]")
assertEql(show[(Int, String)], "scala.Tuple2[scala.Int, scala.Predef.String]")
assertEql(show[[X] =>> X match { case Int => Int }],
assert(show[x.type] == "x.type")
assert(show[Nil.type] == "scala.Nil.type")
assert(show[Int] == "scala.Int")
assert(show[Int => Int] == "scala.Function1[scala.Int, scala.Int]")
assert(show[(Int, String)] == "scala.Tuple2[scala.Int, scala.Predef.String]")
assert(show[[X] =>> X match { case Int => Int }] ==
"""[X >: scala.Nothing <: scala.Any] => X match {
| case scala.Int => scala.Int
|}""".stripMargin)
assertEql(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(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), """+ // match type bound
"""ParamRef(binder, 0), """+
"""List("""+
"""MatchCase("""+
"""TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int"), """+
"""TypeRef(TermRef(ThisType(TypeRef(NoPrefix(), "<root>")), "scala"), "Int")))))""")
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")))))""")

// TODO: more complex types:
// - implicit function types
Expand Down
Loading