From 00f11a3b782b84068808ffdd0e4fe16c69f646a8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 19 Jan 2024 10:03:35 +0100 Subject: [PATCH] Fix `TypeTreeTypeTest` to not match `TypeBoundsTree`s Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec ``` * +- TypeTree ----+- Inferred * | +- ... * | ... * +- TypeBoundsTree ``` Fixes #19480 --- .../src/scala/quoted/runtime/impl/QuotesImpl.scala | 2 +- tests/pos-macros/i19480/Macro_1.scala | 11 +++++++++++ tests/pos-macros/i19480/Test_2.scala | 1 + tests/pos-macros/i19480b/Macro_1.scala | 11 +++++++++++ tests/pos-macros/i19480b/Test_2.scala | 1 + 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i19480/Macro_1.scala create mode 100644 tests/pos-macros/i19480/Test_2.scala create mode 100644 tests/pos-macros/i19480b/Macro_1.scala create mode 100644 tests/pos-macros/i19480b/Test_2.scala diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 04d8d7bc51a0..c802d2a9201d 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1105,7 +1105,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object TypeTreeTypeTest extends TypeTest[Tree, TypeTree]: def unapply(x: Tree): Option[TypeTree & x.type] = x match - case x: (tpd.TypeBoundsTree & x.type) => None + case TypeBoundsTreeTypeTest(_) => None case x: (tpd.Tree & x.type) if x.isType => Some(x) case _ => None end TypeTreeTypeTest diff --git a/tests/pos-macros/i19480/Macro_1.scala b/tests/pos-macros/i19480/Macro_1.scala new file mode 100644 index 000000000000..bf3ea577a20e --- /dev/null +++ b/tests/pos-macros/i19480/Macro_1.scala @@ -0,0 +1,11 @@ +import scala.quoted.* + +inline def whatever: Int = ${whateverImpl} + +def whateverImpl(using Quotes): Expr[Int] = { + import quotes.reflect.* + val t = '{class K[T]}.asTerm + object mapper extends TreeMap + mapper.transformTree(t)(Symbol.spliceOwner) + '{42} +} diff --git a/tests/pos-macros/i19480/Test_2.scala b/tests/pos-macros/i19480/Test_2.scala new file mode 100644 index 000000000000..f12d2935bb9a --- /dev/null +++ b/tests/pos-macros/i19480/Test_2.scala @@ -0,0 +1 @@ +def test = whatever diff --git a/tests/pos-macros/i19480b/Macro_1.scala b/tests/pos-macros/i19480b/Macro_1.scala new file mode 100644 index 000000000000..150c0e93002d --- /dev/null +++ b/tests/pos-macros/i19480b/Macro_1.scala @@ -0,0 +1,11 @@ +import scala.quoted.* + +inline def whatever: Int = ${whateverImpl} + +def whateverImpl(using Quotes): Expr[Int] = { + import quotes.reflect.* + val t = '{class K[T[_]]}.asTerm + object mapper extends TreeMap + mapper.transformTree(t)(Symbol.spliceOwner) + '{42} +} diff --git a/tests/pos-macros/i19480b/Test_2.scala b/tests/pos-macros/i19480b/Test_2.scala new file mode 100644 index 000000000000..f12d2935bb9a --- /dev/null +++ b/tests/pos-macros/i19480b/Test_2.scala @@ -0,0 +1 @@ +def test = whatever