Skip to content

Commit f09da52

Browse files
Merge pull request #12040 from dotty-staging/add-TermParamClause.isErased
Add `TermParamClause.isErased`
2 parents b44cafa + b39fe3b commit f09da52

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
15121512
self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Implicit)
15131513
def isGiven: Boolean =
15141514
self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Given)
1515+
def isErased: Boolean =
1516+
self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Erased)
15151517
end TermParamClauseMethods
15161518

15171519
type TypeParamClause = List[tpd.TypeDef]

library/src/scala/quoted/Quotes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
21602160
def isImplicit: Boolean
21612161
/** Is this a given parameter clause `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
21622162
def isGiven: Boolean
2163+
/** Is this a erased parameter clause `(erased x1: X1, ..., xn: Xn)` */
2164+
def isErased: Boolean
21632165
end TermParamClauseMethods
21642166

21652167
/** A type parameter clause `[X1, ..., Xn]` */

tests/run-macros/i12021.check

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
X1: (i: scala.Int) isImplicit=true, isGiven=false
2-
X2: (i: scala.Int) isImplicit=false, isGiven=true
1+
X1: (i: scala.Int) isImplicit=true, isGiven=false, isErased=false
2+
X2: (i: scala.Int) isImplicit=false, isGiven=true, isErased=false
3+
X3: (i: scala.Int) isImplicit=false, isGiven=false, isErased=true

tests/run-macros/i12021/Macro_1.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ inline def inspect[A]: String =
66
def inspect2[A: Type](using Quotes): Expr[String] = {
77
import quotes.reflect.*
88

9-
val DefDef(_, List(Nil, ps: TermParamClause), _, _) =
10-
TypeRepr.of[A].typeSymbol.primaryConstructor.tree
9+
val ps =
10+
TypeRepr.of[A].typeSymbol.primaryConstructor.tree match
11+
case DefDef(_, List(Nil, ps: TermParamClause), _, _) => ps
12+
case DefDef(_, List(ps: TermParamClause), _, _) => ps
1113

1214
val names = ps.params.map(p => s"${p.name}: ${p.tpt.show}").mkString("(", ", ", ")")
1315

14-
Expr(s"${Type.show[A]}: $names isImplicit=${ps.isImplicit}, isGiven=${ps.isGiven}")
16+
Expr(s"${Type.show[A]}: $names isImplicit=${ps.isImplicit}, isGiven=${ps.isGiven}, isErased=${ps.isErased}")
1517
}

tests/run-macros/i12021/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import scala.language.experimental.erasedDefinitions
12

23
class X1(implicit i: Int)
34
class X2(using i: Int)
5+
class X3(erased i: Int)
46

57
@main def Test = {
68
println(inspect[X1])
79
println(inspect[X2])
10+
println(inspect[X3])
811
}

0 commit comments

Comments
 (0)