Skip to content

Add TermParamClause.isErased #12040

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
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
2 changes: 2 additions & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Implicit)
def isGiven: Boolean =
self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Given)
def isErased: Boolean =
self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Erased)
end TermParamClauseMethods

type TypeParamClause = List[tpd.TypeDef]
Expand Down
2 changes: 2 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
def isImplicit: Boolean
/** Is this a given parameter clause `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */
def isGiven: Boolean
/** Is this a erased parameter clause `(erased x1: X1, ..., xn: Xn)` */
def isErased: Boolean
end TermParamClauseMethods

/** A type parameter clause `[X1, ..., Xn]` */
Expand Down
5 changes: 3 additions & 2 deletions tests/run-macros/i12021.check
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
X1: (i: scala.Int) isImplicit=true, isGiven=false
X2: (i: scala.Int) isImplicit=false, isGiven=true
X1: (i: scala.Int) isImplicit=true, isGiven=false, isErased=false
X2: (i: scala.Int) isImplicit=false, isGiven=true, isErased=false
X3: (i: scala.Int) isImplicit=false, isGiven=false, isErased=true
8 changes: 5 additions & 3 deletions tests/run-macros/i12021/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ inline def inspect[A]: String =
def inspect2[A: Type](using Quotes): Expr[String] = {
import quotes.reflect.*

val DefDef(_, List(Nil, ps: TermParamClause), _, _) =
TypeRepr.of[A].typeSymbol.primaryConstructor.tree
val ps =
TypeRepr.of[A].typeSymbol.primaryConstructor.tree match
case DefDef(_, List(Nil, ps: TermParamClause), _, _) => ps
case DefDef(_, List(ps: TermParamClause), _, _) => ps

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

Expr(s"${Type.show[A]}: $names isImplicit=${ps.isImplicit}, isGiven=${ps.isGiven}")
Expr(s"${Type.show[A]}: $names isImplicit=${ps.isImplicit}, isGiven=${ps.isGiven}, isErased=${ps.isErased}")
}
3 changes: 3 additions & 0 deletions tests/run-macros/i12021/Test_2.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import scala.language.experimental.erasedDefinitions

class X1(implicit i: Int)
class X2(using i: Int)
class X3(erased i: Int)

@main def Test = {
println(inspect[X1])
println(inspect[X2])
println(inspect[X3])
}