From ad50bf9d62806a75ed8e6a08180d4b024148a400 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 6 Mar 2020 11:01:31 +0100 Subject: [PATCH] Fix #8389, fix #8364: Hande immutable.Seq --- .../tasty/reflect/SourceCodePrinter.scala | 4 ++- .../tasty-inspector/i8364.scala | 12 +++++++ .../tasty-inspector/i8389.scala | 32 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/run-custom-args/tasty-inspector/i8364.scala create mode 100644 tests/run-custom-args/tasty-inspector/i8389.scala diff --git a/library/src/scala/tasty/reflect/SourceCodePrinter.scala b/library/src/scala/tasty/reflect/SourceCodePrinter.scala index c77dc92ef0d5..4736ed5fa0df 100644 --- a/library/src/scala/tasty/reflect/SourceCodePrinter.scala +++ b/library/src/scala/tasty/reflect/SourceCodePrinter.scala @@ -1443,7 +1443,9 @@ class SourceCodePrinter[R <: Reflection & Singleton](val tasty: R)(syntaxHighlig object Sequence { def unapply(tpe: Type)(using ctx: Context): Option[Type] = tpe match { - case AppliedType(seq, (tp: Type) :: Nil) if seq.typeSymbol == ctx.requiredClass("scala.collection.Seq") => Some(tp) + case AppliedType(seq, (tp: Type) :: Nil) + if seq.typeSymbol == ctx.requiredClass("scala.collection.Seq") || seq.typeSymbol == ctx.requiredClass("scala.collection.immutable.Seq") => + Some(tp) case _ => None } } diff --git a/tests/run-custom-args/tasty-inspector/i8364.scala b/tests/run-custom-args/tasty-inspector/i8364.scala new file mode 100644 index 000000000000..9080163f8433 --- /dev/null +++ b/tests/run-custom-args/tasty-inspector/i8364.scala @@ -0,0 +1,12 @@ +import scala.tasty._ +import scala.tasty.inspector._ + +@main def Test = { + val inspector = new TastyInspector { + def processCompilationUnit(reflect: Reflection)(tree: reflect.Tree): Unit = { + import reflect.{_, given _} + println(tree.show) + } + } + inspector.inspect("", List("scala.tasty.Reflection")) +} diff --git a/tests/run-custom-args/tasty-inspector/i8389.scala b/tests/run-custom-args/tasty-inspector/i8389.scala new file mode 100644 index 000000000000..9b047efd9801 --- /dev/null +++ b/tests/run-custom-args/tasty-inspector/i8389.scala @@ -0,0 +1,32 @@ +import scala.tasty._ +import scala.tasty.inspector._ + +@main def Test = { + // in dotty-example-project + val inspector = new TastyInspector { + def processCompilationUnit(reflect: Reflection)(tree: reflect.Tree): Unit = { + import reflect.{_, given _} + println(tree.show) + } + } + inspector.inspect("", List("TraitParams")) +} + +object TraitParams { + + trait Base(val msg: String) + class A extends Base("Hello") + class B extends Base("Dotty!") + + // Union types only exist in Dotty, so there's no chance that this will accidentally be compiled with Scala 2 + private def printMessages(msgs: (A | B)*) = println(msgs.map(_.msg).mkString(" ")) + + def test: Unit = { + + printMessages(new A, new B) + + // Sanity check the classpath: this won't run if the dotty jar is not present. + val x: Int => Int = z => z + x(1) + } +}