Skip to content

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

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 7 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix run-macros/type-show
[Cherry-picked db1dcdc][modified]
  • Loading branch information
WojciechMazur committed Jul 2, 2024
commit 59ab8494bcf9f4f1206b80e92a6f5116d8ad12a4
30 changes: 23 additions & 7 deletions tests/run-macros/type-show/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@

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
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 }] ==
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 }],
"""[X >: scala.Nothing <: scala.Any] => X match {
| case scala.Int => scala.Int
|}""".stripMargin)
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")))))""")
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")))))""")

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