Skip to content

Backport some fixes from #12200 #12227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions tests/pos-macros/i11835/X.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
'{()}
2 changes: 1 addition & 1 deletion tests/run-macros/tasty-extractors-1.check
Original file line number Diff line number Diff line change
Expand Up @@ -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()))))))
Expand Down