From b39fe3bbbaeeefacffab04e532918d832b2f3093 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 9 Apr 2021 11:09:13 +0200 Subject: [PATCH] Add `TermParamClause.isErased` --- compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala | 2 ++ library/src/scala/quoted/Quotes.scala | 2 ++ tests/run-macros/i12021.check | 5 +++-- tests/run-macros/i12021/Macro_1.scala | 8 +++++--- tests/run-macros/i12021/Test_2.scala | 3 +++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index efed80239b88..9a1df9d01f2d 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -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] diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index d97be901355a..a864a4b3fd3b 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -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]` */ diff --git a/tests/run-macros/i12021.check b/tests/run-macros/i12021.check index dccff2b4e6a5..b244dce80b34 100644 --- a/tests/run-macros/i12021.check +++ b/tests/run-macros/i12021.check @@ -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 diff --git a/tests/run-macros/i12021/Macro_1.scala b/tests/run-macros/i12021/Macro_1.scala index 89dcaaaf5634..4c10cf2ca17d 100644 --- a/tests/run-macros/i12021/Macro_1.scala +++ b/tests/run-macros/i12021/Macro_1.scala @@ -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}") } diff --git a/tests/run-macros/i12021/Test_2.scala b/tests/run-macros/i12021/Test_2.scala index 96683b2c6583..17f74792ece4 100644 --- a/tests/run-macros/i12021/Test_2.scala +++ b/tests/run-macros/i12021/Test_2.scala @@ -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]) } \ No newline at end of file