From 869af6d9e5eca66ebc7b8369be4a18726383fe60 Mon Sep 17 00:00:00 2001 From: Ruslan Shevchenko Date: Tue, 1 Feb 2022 10:55:05 +0200 Subject: [PATCH] fix #14393 --- library/src/scala/quoted/Quotes.scala | 2 ++ tests/pos-macros/i14393/Macro_1.scala | 20 ++++++++++++++++++++ tests/pos-macros/i14393/Test_2.scala | 11 +++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/pos-macros/i14393/Macro_1.scala create mode 100644 tests/pos-macros/i14393/Test_2.scala diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 88eecad65485..a9e2db108f40 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -4391,6 +4391,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => foldTree(x, tpt)(owner) case Typed(expr, tpt) => foldTree(foldTree(x, expr)(owner), tpt)(owner) + case TypedOrTest(expr, tpt) => + foldTree(foldTree(x, expr)(owner), tpt)(owner) case NamedArg(_, arg) => foldTree(x, arg)(owner) case Assign(lhs, rhs) => diff --git a/tests/pos-macros/i14393/Macro_1.scala b/tests/pos-macros/i14393/Macro_1.scala new file mode 100644 index 000000000000..16ce1e4d4d72 --- /dev/null +++ b/tests/pos-macros/i14393/Macro_1.scala @@ -0,0 +1,20 @@ +package i14393 +import scala.quoted.* + +object M { + + inline def useFoldTree[X](inline x:X):X = ${ + useFoldTreeImpl('x) + } + + def useFoldTreeImpl[X:Type](x:Expr[X])(using Quotes):Expr[X] = { + import quotes.reflect.* + val search = new TreeAccumulator[Int] { + def foldTree(s:Int, tree: Tree)(owner: Symbol): Int = + foldOverTree(s,tree)(owner) + } + search.foldTree(0,x.asTerm)(Symbol.spliceOwner) + x + } + +} diff --git a/tests/pos-macros/i14393/Test_2.scala b/tests/pos-macros/i14393/Test_2.scala new file mode 100644 index 000000000000..911e82da0424 --- /dev/null +++ b/tests/pos-macros/i14393/Test_2.scala @@ -0,0 +1,11 @@ +package i14393 + +def thing() = + M.useFoldTree { + + Option("") match + case None => + case Some(_) => + ??? + + }