From 5e8493743596e6f2f7febeaf9ebf768434110c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Sun, 14 Nov 2021 22:08:50 +0100 Subject: [PATCH 1/6] Failing test for #13947 --- tests/run-macros/i13947.check | 2 ++ tests/run-macros/i13947/Macro_1.scala | 12 ++++++++++++ tests/run-macros/i13947/Test_2.scala | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 tests/run-macros/i13947.check create mode 100644 tests/run-macros/i13947/Macro_1.scala create mode 100644 tests/run-macros/i13947/Test_2.scala diff --git a/tests/run-macros/i13947.check b/tests/run-macros/i13947.check new file mode 100644 index 000000000000..a6662ad6aa43 --- /dev/null +++ b/tests/run-macros/i13947.check @@ -0,0 +1,2 @@ +scala.Predef.String +scala.Int, scala.Float, scala.Long \ No newline at end of file diff --git a/tests/run-macros/i13947/Macro_1.scala b/tests/run-macros/i13947/Macro_1.scala new file mode 100644 index 000000000000..45ec6be313d2 --- /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 tparams: List[TypeRepr] = TypeRepr.of[A].typeParams + val debug = tparams.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..2164794c6d0d --- /dev/null +++ b/tests/run-macros/i13947/Test_2.scala @@ -0,0 +1,3 @@ +@main def Test: Unit = + printTypeParams[Option[String]] + printTypeParams[Function2[Int, Float, Long]] From f3a7b1e45dd29cf01bca7e81b737a3ef0498336f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Sun, 14 Nov 2021 22:27:39 +0100 Subject: [PATCH 2/6] Fix #13947 --- compiler/src/dotty/tools/dotc/core/Symbols.scala | 1 - compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 5 +++++ library/src/scala/quoted/Quotes.scala | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) 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..6581f306505c 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 typeParams: 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..3a0808b4285b 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 type parameters */ + @experimental + def typeParams: List[TypeRepr] end extension } From 0962c96c52bd6e1539d1ba5ea02a735bdcf544c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Mon, 15 Nov 2021 09:28:09 +0100 Subject: [PATCH 3/6] Update MiMa filters --- project/MiMaFilters.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project/MiMaFilters.scala b/project/MiMaFilters.scala index ae3673016db1..bc1b967041d6 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.typeParams"), + ProblemFilters.exclude[DirectMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.typeParams"), // Should have been added in 3.1.0 // These are only allowed on imports and therefore should not be present in binaries emitted before From 219bf7c73d42400d0ecb88c89ceb012fca277675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Mon, 15 Nov 2021 11:08:26 +0100 Subject: [PATCH 4/6] Update documentation & tests --- library/src/scala/quoted/Quotes.scala | 2 +- tests/run-macros/i13947.check | 5 +++-- tests/run-macros/i13947/Macro_1.scala | 2 +- tests/run-macros/i13947/Test_2.scala | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 3a0808b4285b..8a304a535f9f 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -2571,7 +2571,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => @experimental def substituteTypes(from: List[Symbol], to: List[TypeRepr]): TypeRepr - /** The type parameters */ + /** The applied type parameters (empty if there is no such parameters) */ @experimental def typeParams: List[TypeRepr] end extension diff --git a/tests/run-macros/i13947.check b/tests/run-macros/i13947.check index a6662ad6aa43..674afdfa11eb 100644 --- a/tests/run-macros/i13947.check +++ b/tests/run-macros/i13947.check @@ -1,2 +1,3 @@ -scala.Predef.String -scala.Int, scala.Float, scala.Long \ No newline at end of file +[] +[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 index 45ec6be313d2..cb39d52a3ffb 100644 --- a/tests/run-macros/i13947/Macro_1.scala +++ b/tests/run-macros/i13947/Macro_1.scala @@ -6,7 +6,7 @@ def printTypeParamsImpl[A: Type](using q: Quotes): Expr[Unit] = { import q.reflect.* val tparams: List[TypeRepr] = TypeRepr.of[A].typeParams - val debug = tparams.map(_.show).mkString(", ") + val debug = tparams.map(_.show).mkString("[", ", ", "]") '{ println(${Expr(debug)}) } } diff --git a/tests/run-macros/i13947/Test_2.scala b/tests/run-macros/i13947/Test_2.scala index 2164794c6d0d..009193cf12b8 100644 --- a/tests/run-macros/i13947/Test_2.scala +++ b/tests/run-macros/i13947/Test_2.scala @@ -1,3 +1,4 @@ @main def Test: Unit = + printTypeParams[scala.util.Random] printTypeParams[Option[String]] printTypeParams[Function2[Int, Float, Long]] From 14f02973a7e78e6e613252d5b2a226246a2bccc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Mon, 15 Nov 2021 13:53:06 +0100 Subject: [PATCH 5/6] Updating naming --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 2 +- library/src/scala/quoted/Quotes.scala | 2 +- tests/run-macros/i13947/Macro_1.scala | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 6581f306505c..3de7f0bfc670 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1750,7 +1750,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def substituteTypes(from: List[Symbol], to: List[TypeRepr]): TypeRepr = self.subst(from, to) - def typeParams: List[TypeRepr] = self match + def typeArgs: List[TypeRepr] = self match case AppliedType(_, args) => args case _ => List.empty end extension diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 8a304a535f9f..c48023db5973 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -2573,7 +2573,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** The applied type parameters (empty if there is no such parameters) */ @experimental - def typeParams: List[TypeRepr] + def typeArgs: List[TypeRepr] end extension } diff --git a/tests/run-macros/i13947/Macro_1.scala b/tests/run-macros/i13947/Macro_1.scala index cb39d52a3ffb..10f5930170fe 100644 --- a/tests/run-macros/i13947/Macro_1.scala +++ b/tests/run-macros/i13947/Macro_1.scala @@ -5,8 +5,8 @@ inline def printTypeParams[A]: Unit = ${ printTypeParamsImpl[A] } def printTypeParamsImpl[A: Type](using q: Quotes): Expr[Unit] = { import q.reflect.* - val tparams: List[TypeRepr] = TypeRepr.of[A].typeParams - val debug = tparams.map(_.show).mkString("[", ", ", "]") + val targs: List[TypeRepr] = TypeRepr.of[A].typeArgs + val debug = targs.map(_.show).mkString("[", ", ", "]") '{ println(${Expr(debug)}) } } From c6c09dfde6c6702c6f735b2d701f12d0e2a8b1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Chantepie?= Date: Mon, 15 Nov 2021 15:21:49 +0100 Subject: [PATCH 6/6] Fix MiMa --- library/src/scala/quoted/Quotes.scala | 2 +- project/MiMaFilters.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index c48023db5973..a375709844db 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -2571,7 +2571,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => @experimental def substituteTypes(from: List[Symbol], to: List[TypeRepr]): TypeRepr - /** The applied type parameters (empty if there is no such parameters) */ + /** 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 bc1b967041d6..0a7b321cf319 100644 --- a/project/MiMaFilters.scala +++ b/project/MiMaFilters.scala @@ -9,8 +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.typeParams"), - ProblemFilters.exclude[DirectMissingMethodProblem]("scala.quoted.Quotes#reflectModule#TypeReprMethods.typeParams"), + 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