Skip to content

Commit

Permalink
Fix run-macros/type-show
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Feb 28, 2024
1 parent 2423198 commit db1dcdc
Showing 1 changed file with 23 additions and 7 deletions.
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

0 comments on commit db1dcdc

Please sign in to comment.