diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index b6379d7c8434..efed80239b88 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1510,6 +1510,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def params: List[ValDef] = self def isImplicit: Boolean = self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Implicit) + def isGiven: Boolean = + self.nonEmpty && self.head.symbol.is(dotc.core.Flags.Given) end TermParamClauseMethods type TypeParamClause = List[tpd.TypeDef] diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index ea593090c9a0..d97be901355a 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -2156,8 +2156,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => extension (self: TermParamClause) /** List of parameters of the clause */ def params: List[ValDef] - /** Is this a given parameter clause `(implicit X1, ..., Xn)`, `(given X1, ..., Xn)` or `(given x1: X1, ..., xn: Xn)` */ + /** Is this an implicit parameter clause `(implicit x1: X1, ..., xn: Xn)` */ def isImplicit: Boolean + /** Is this a given parameter clause `(using X1, ..., Xn)` or `(using x1: X1, ..., xn: Xn)` */ + def isGiven: Boolean end TermParamClauseMethods /** A type parameter clause `[X1, ..., Xn]` */ diff --git a/tests/run-macros/i12021.check b/tests/run-macros/i12021.check new file mode 100644 index 000000000000..dccff2b4e6a5 --- /dev/null +++ b/tests/run-macros/i12021.check @@ -0,0 +1,2 @@ +X1: (i: scala.Int) isImplicit=true, isGiven=false +X2: (i: scala.Int) isImplicit=false, isGiven=true diff --git a/tests/run-macros/i12021/Macro_1.scala b/tests/run-macros/i12021/Macro_1.scala new file mode 100644 index 000000000000..89dcaaaf5634 --- /dev/null +++ b/tests/run-macros/i12021/Macro_1.scala @@ -0,0 +1,15 @@ +import scala.quoted.* + +inline def inspect[A]: String = + ${ inspect2[A] } + +def inspect2[A: Type](using Quotes): Expr[String] = { + import quotes.reflect.* + + val DefDef(_, List(Nil, ps: TermParamClause), _, _) = + TypeRepr.of[A].typeSymbol.primaryConstructor.tree + + 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}") +} diff --git a/tests/run-macros/i12021/Test_2.scala b/tests/run-macros/i12021/Test_2.scala new file mode 100644 index 000000000000..96683b2c6583 --- /dev/null +++ b/tests/run-macros/i12021/Test_2.scala @@ -0,0 +1,8 @@ + +class X1(implicit i: Int) +class X2(using i: Int) + +@main def Test = { + println(inspect[X1]) + println(inspect[X2]) +} \ No newline at end of file