diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index e49399ff9791..67e51ce638d4 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -36,7 +36,6 @@ import scala.annotation.internal.sharable import config.Printers.typr object Symbols { - implicit def eqSymbol: CanEqual[Symbol, Symbol] = CanEqual.derived /** Tree attachment containing the identifiers in a tree as a sorted array */ diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index d6e13fbbd168..3de7f0bfc670 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1749,6 +1749,10 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler dotc.core.Types.decorateTypeApplications(self).appliedTo(targs) def substituteTypes(from: List[Symbol], to: List[TypeRepr]): TypeRepr = self.subst(from, to) + + def typeArgs: List[TypeRepr] = self match + case AppliedType(_, args) => args + case _ => List.empty end extension end TypeReprMethods @@ -2480,6 +2484,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def name: String = self.denot.name.toString def fullName: String = self.denot.fullName.toString + def pos: Option[Position] = if self.exists then Some(self.sourcePos) else None diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 397f9d3b6aae..a375709844db 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -2571,6 +2571,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => @experimental def substituteTypes(from: List[Symbol], to: List[TypeRepr]): TypeRepr + /** The applied type arguments (empty if there is no such arguments) */ + @experimental + def typeArgs: List[TypeRepr] end extension } diff --git a/project/MiMaFilters.scala b/project/MiMaFilters.scala index ae3673016db1..0a7b321cf319 100644 --- a/project/MiMaFilters.scala +++ b/project/MiMaFilters.scala @@ -9,6 +9,8 @@ object MiMaFilters { ProblemFilters.exclude[DirectMissingMethodProblem]("scala.runtime.Tuples.append"), ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.substituteTypes"), ProblemFilters.exclude[DirectMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.substituteTypes"), + ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.typeArgs"), + ProblemFilters.exclude[DirectMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.typeArgs"), // Should have been added in 3.1.0 // These are only allowed on imports and therefore should not be present in binaries emitted before diff --git a/tests/run-macros/i13947.check b/tests/run-macros/i13947.check new file mode 100644 index 000000000000..674afdfa11eb --- /dev/null +++ b/tests/run-macros/i13947.check @@ -0,0 +1,3 @@ +[] +[scala.Predef.String] +[scala.Int, scala.Float, scala.Long] diff --git a/tests/run-macros/i13947/Macro_1.scala b/tests/run-macros/i13947/Macro_1.scala new file mode 100644 index 000000000000..10f5930170fe --- /dev/null +++ b/tests/run-macros/i13947/Macro_1.scala @@ -0,0 +1,12 @@ +import scala.quoted.* + +inline def printTypeParams[A]: Unit = ${ printTypeParamsImpl[A] } + +def printTypeParamsImpl[A: Type](using q: Quotes): Expr[Unit] = { + import q.reflect.* + + val targs: List[TypeRepr] = TypeRepr.of[A].typeArgs + val debug = targs.map(_.show).mkString("[", ", ", "]") + + '{ println(${Expr(debug)}) } +} diff --git a/tests/run-macros/i13947/Test_2.scala b/tests/run-macros/i13947/Test_2.scala new file mode 100644 index 000000000000..009193cf12b8 --- /dev/null +++ b/tests/run-macros/i13947/Test_2.scala @@ -0,0 +1,4 @@ +@main def Test: Unit = + printTypeParams[scala.util.Random] + printTypeParams[Option[String]] + printTypeParams[Function2[Int, Float, Long]]