Skip to content

Commit 53651f5

Browse files
Merge pull request #12227 from dotty-staging/backport-reflection-fixes
Backport some fixes from #12200
2 parents 1e484e5 + 5d5a564 commit 53651f5

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
9797
new ExprImpl(self, SpliceScope.getCurrent)
9898
else self match
9999
case TermTypeTest(self) => throw new Exception("Expected an expression. This is a partially applied Term. Try eta-expanding the term first.")
100-
case _ => throw new Exception("Expected a Term but was: " + self)
100+
case _ => throw new Exception("Expected a Term but was: " + Printer.TreeStructure.show(self))
101101
end extension
102102

103103
extension (self: Tree)
@@ -186,10 +186,11 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
186186

187187
object StatementTypeTest extends TypeTest[Tree, Statement]:
188188
def unapply(x: Tree): Option[Statement & x.type] = x match
189-
case _: tpd.PatternTree => None
190-
case _ =>
191-
if x.isTerm then TermTypeTest.unapply(x)
192-
else DefinitionTypeTest.unapply(x)
189+
case TermTypeTest(x: x.type) => Some(x)
190+
case DefinitionTypeTest(x: x.type) => Some(x)
191+
case ImportTypeTest(x: x.type) => Some(x)
192+
case ExportTypeTest(x: x.type) => Some(x)
193+
case _ => None
193194
end StatementTypeTest
194195

195196
type Definition = tpd.MemberDef
@@ -1021,7 +1022,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
10211022

10221023
object TypeIdentTypeTest extends TypeTest[Tree, TypeIdent]:
10231024
def unapply(x: Tree): Option[TypeIdent & x.type] = x match
1024-
case tpt: (tpd.Ident & x.type) if tpt.isType => Some(tpt)
1025+
case tpt: (tpd.Ident & x.type) if tpt.isType && tpt.name != nme.WILDCARD => Some(tpt)
10251026
case _ => None
10261027
end TypeIdentTypeTest
10271028

@@ -1335,7 +1336,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
13351336

13361337
object WildcardTypeTreeTypeTest extends TypeTest[Tree, WildcardTypeTree]:
13371338
def unapply(x: Tree): Option[WildcardTypeTree & x.type] = x match
1338-
case x: (tpd.Ident & x.type) if x.name == nme.WILDCARD => Some(x)
1339+
case x: (tpd.Ident & x.type) if x.isType && x.name == nme.WILDCARD => Some(x)
13391340
case _ => None
13401341
end WildcardTypeTreeTypeTest
13411342

compiler/src/scala/quoted/runtime/impl/printers/Extractors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ object Extractors {
170170
case Unapply(fun, implicits, patterns) =>
171171
this += "Unapply(" += fun += ", " ++= implicits += ", " ++= patterns += ")"
172172
case Alternatives(patterns) =>
173-
this += "Alternative(" ++= patterns += ")"
173+
this += "Alternatives(" ++= patterns += ")"
174174
}
175175

176176
def visitConstant(x: Constant): this.type = x match {

tests/pos-macros/i11835/X.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ object X:
66

77
private def _blah(b: Expr[Boolean])(using Quotes): Expr[Unit] =
88
import quotes.reflect.*
9-
println("="*120)
10-
println(b.asTerm)
11-
println(b.valueOrError)
9+
b.asTerm
10+
b.valueOrError
1211
'{()}

tests/run-macros/tasty-extractors-1.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")
5252
Inlined(None, Nil, Match(Literal(StringConstant("f")), List(CaseDef(Typed(Ident("_"), TypeIdent("String")), None, Block(Nil, Literal(UnitConstant()))))))
5353
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")
5454

55-
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()))))))
55+
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()))))))
5656
TypeRef(ThisType(TypeRef(NoPrefix(), "scala")), "Unit")
5757

5858
Inlined(None, Nil, Match(Literal(StringConstant("h")), List(CaseDef(Ident("_"), Some(Literal(BooleanConstant(false))), Block(Nil, Literal(UnitConstant()))))))

0 commit comments

Comments
 (0)