diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 9a1df9d01f2d..6fdf2225bbdf 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -97,7 +97,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler new ExprImpl(self, SpliceScope.getCurrent) else self match case TermTypeTest(self) => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.") - case _ => throw new Exception("Expected a Term but was: " + self) + case _ => throw new Exception("Expected a Term but was: " + Printer.TreeStructure.show(self)) end extension extension (self: Tree) @@ -186,10 +186,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object StatementTypeTest extends TypeTest[Tree, Statement]: def unapply(x: Tree): Option[Statement & x.type] = x match - case _: tpd.PatternTree => None - case _ => - if x.isTerm then TermTypeTest.unapply(x) - else DefinitionTypeTest.unapply(x) + case TermTypeTest(x: x.type) => Some(x) + case DefinitionTypeTest(x: x.type) => Some(x) + case ImportTypeTest(x: x.type) => Some(x) + case ExportTypeTest(x: x.type) => Some(x) + case _ => None end StatementTypeTest type Definition = tpd.MemberDef @@ -1021,7 +1022,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object TypeIdentTypeTest extends TypeTest[Tree, TypeIdent]: def unapply(x: Tree): Option[TypeIdent & x.type] = x match - case tpt: (tpd.Ident & x.type) if tpt.isType => Some(tpt) + case tpt: (tpd.Ident & x.type) if tpt.isType && tpt.name != nme.WILDCARD => Some(tpt) case _ => None end TypeIdentTypeTest @@ -1335,7 +1336,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object WildcardTypeTreeTypeTest extends TypeTest[Tree, WildcardTypeTree]: def unapply(x: Tree): Option[WildcardTypeTree & x.type] = x match - case x: (tpd.Ident & x.type) if x.name == nme.WILDCARD => Some(x) + case x: (tpd.Ident & x.type) if x.isType && x.name == nme.WILDCARD => Some(x) case _ => None end WildcardTypeTreeTypeTest diff --git a/compiler/src/scala/quoted/runtime/impl/printers/Extractors.scala b/compiler/src/scala/quoted/runtime/impl/printers/Extractors.scala index b55ae6cbb166..b7502e44bc4a 100644 --- a/compiler/src/scala/quoted/runtime/impl/printers/Extractors.scala +++ b/compiler/src/scala/quoted/runtime/impl/printers/Extractors.scala @@ -170,7 +170,7 @@ object Extractors { case Unapply(fun, implicits, patterns) => this += "Unapply(" += fun += ", " ++= implicits += ", " ++= patterns += ")" case Alternatives(patterns) => - this += "Alternative(" ++= patterns += ")" + this += "Alternatives(" ++= patterns += ")" } def visitConstant(x: Constant): this.type = x match { diff --git a/tests/pos-macros/i11835/X.scala b/tests/pos-macros/i11835/X.scala index ccc05e9e57c3..a298c0345f03 100644 --- a/tests/pos-macros/i11835/X.scala +++ b/tests/pos-macros/i11835/X.scala @@ -6,7 +6,6 @@ object X: private def _blah(b: Expr[Boolean])(using Quotes): Expr[Unit] = import quotes.reflect.* - println("="*120) - println(b.asTerm) - println(b.valueOrError) + b.asTerm + b.valueOrError '{()} diff --git a/tests/run-macros/tasty-extractors-1.check b/tests/run-macros/tasty-extractors-1.check index b53e72c1f378..5e7a330779eb 100644 --- a/tests/run-macros/tasty-extractors-1.check +++ b/tests/run-macros/tasty-extractors-1.check @@ -52,7 +52,7 @@ TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Match(Literal(StringConstant("f")), List(CaseDef(Typed(Ident("_"), TypeIdent("String")), None, Block(Nil, Literal(UnitConstant())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") -Inlined(None, Nil, Match(Typed(Literal(StringConstant("g")), TypeIdent("Any")), List(CaseDef(Alternative(List(Typed(Ident("_"), TypeIdent("String")), Typed(Ident("_"), TypeIdent("Int")))), None, Block(Nil, Literal(UnitConstant())))))) +Inlined(None, Nil, Match(Typed(Literal(StringConstant("g")), TypeIdent("Any")), List(CaseDef(Alternatives(List(Typed(Ident("_"), TypeIdent("String")), Typed(Ident("_"), TypeIdent("Int")))), None, Block(Nil, Literal(UnitConstant())))))) TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit") Inlined(None, Nil, Match(Literal(StringConstant("h")), List(CaseDef(Ident("_"), Some(Literal(BooleanConstant(false))), Block(Nil, Literal(UnitConstant()))))))