From 50cd1bd62a4c11baa2d538f1acfbfe4a7e546d95 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Apr 2021 17:09:33 +0200 Subject: [PATCH 1/5] Fix asExpr error message --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 9a1df9d01f2d..b6e78870470d 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) From a9120ca5c5cfe9da954169c5b68fbfaa247b88d3 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Apr 2021 17:13:13 +0200 Subject: [PATCH 2/5] Fix typo in Alternatives printer --- .../src/scala/quoted/runtime/impl/printers/Extractors.scala | 2 +- tests/run-macros/tasty-extractors-1.check | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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())))))) From 56b383472d08b6272fae44cf0601a14f59bdc254 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Apr 2021 17:15:43 +0200 Subject: [PATCH 3/5] Fix StatementTypeTest Now it trivially covers all: Import, Export, Definition, Term Previously we missed Import/Export and the optimized version of term testing was incomplete. --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index b6e78870470d..f9d704006315 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -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 From 9b737d006fdd93481ba2cfa84ed3cc57f8341525 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Apr 2021 17:18:37 +0200 Subject: [PATCH 4/5] Fix TypeIdentTypeTest and WildcardTypeTreeTypeTest `TypeIdentTypeTest` would accidentally match `WildcardTypeTree` and `WildcardTypeTreeTypeTest` would accidentally match term `Ident(_)` --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index f9d704006315..6fdf2225bbdf 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1022,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 @@ -1336,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 From 5d5a564e8c59604a007300b2613e02724ab0ff6a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Apr 2021 17:28:02 +0200 Subject: [PATCH 5/5] Do not print while compiling i11835 --- tests/pos-macros/i11835/X.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 '{()}