diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 4d08e0582d1d..64483da71616 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2768,7 +2768,14 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def SomeModule: Symbol = dotc.core.Symbols.defn.SomeClass.companionModule def ProductClass: Symbol = dotc.core.Symbols.defn.ProductClass def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol = + if arity < 0 then throw IllegalArgumentException(s"arity: $arity") dotc.core.Symbols.defn.FunctionSymbol(arity, isImplicit, isErased) + def FunctionClass(arity: Int): Symbol = + if arity < 0 then throw IllegalArgumentException(s"arity: $arity") + dotc.core.Symbols.defn.FunctionSymbol(arity, false, false) + def ContextFunctionClass(arity: Int): Symbol = + if arity < 0 then throw IllegalArgumentException(s"arity: $arity") + dotc.core.Symbols.defn.FunctionSymbol(arity, true, false) def TupleClass(arity: Int): Symbol = dotc.core.Symbols.defn.TupleType(arity).nn.classSymbol.asClass def isTupleClass(sym: Symbol): Boolean = diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index 22ec107aeae8..6435d98263ad 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -4254,8 +4254,26 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => * - ... * - Nth element is `FunctionN` */ + // TODO deprecate in 3.4 and stabilize FunctionClass(Int)/ContextFunctionClass(Int) + @deprecated("Use `FunctionClass` with a single argument or `ContextFunctionClass`","3.4") def FunctionClass(arity: Int, isImplicit: Boolean = false, isErased: Boolean = false): Symbol + /** Class symbol of a function class `scala.FunctionN`. + * + * @param arity the arity of the function where `0 <= arity` + * @return class symbol of `scala.FunctionN` where `N == arity` + */ + @experimental + def FunctionClass(arity: Int): Symbol + + /** Class symbol of a context function class `scala.ContextFunctionN`. + * + * @param arity the arity of the function where `0 <= arity` + * @return class symbol of `scala.ContextFunctionN` where `N == arity` + */ + @experimental + def ContextFunctionClass(arity: Int): Symbol + /** Function-like object that maps arity to symbols for classes `scala.TupleX`. * - 0th element is `NoSymbol` * - 1st element is `NoSymbol` diff --git a/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala b/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala index 30e7c5af6c2a..cfff3718eb7d 100644 --- a/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala +++ b/tests/run-custom-args/tasty-inspector/stdlibExperimentalDefinitions.scala @@ -66,7 +66,10 @@ val experimentalDefinitionInLibrary = Set( "scala.annotation.MacroAnnotation", //// New APIs: Quotes - // Can be stabilized in 3.3.0 (unsure) or later + // Should be stabilized in 3.4.0 + "scala.quoted.Quotes.reflectModule.defnModule.ContextFunctionClass", + "scala.quoted.Quotes.reflectModule.defnModule.FunctionClass", + // Can be stabilized in 3.4.0 (unsure) or later "scala.quoted.Quotes.reflectModule.CompilationInfoModule.XmacroSettings", "scala.quoted.Quotes.reflectModule.FlagsModule.JavaAnnotation", // Cant be stabilized yet. diff --git a/tests/run-macros/tasty-definitions-1.check b/tests/run-macros/tasty-definitions-1.check index 7ee9da3e64e8..c2674c1b7a06 100644 --- a/tests/run-macros/tasty-definitions-1.check +++ b/tests/run-macros/tasty-definitions-1.check @@ -57,31 +57,57 @@ Function23 Function24 Function25 ContextFunction0 +ContextFunction0 +ContextFunction1 ContextFunction1 ContextFunction2 +ContextFunction2 +ContextFunction3 ContextFunction3 ContextFunction4 +ContextFunction4 +ContextFunction5 ContextFunction5 ContextFunction6 +ContextFunction6 ContextFunction7 +ContextFunction7 +ContextFunction8 ContextFunction8 ContextFunction9 +ContextFunction9 ContextFunction10 +ContextFunction10 +ContextFunction11 ContextFunction11 ContextFunction12 +ContextFunction12 ContextFunction13 +ContextFunction13 +ContextFunction14 ContextFunction14 ContextFunction15 +ContextFunction15 +ContextFunction16 ContextFunction16 ContextFunction17 +ContextFunction17 +ContextFunction18 ContextFunction18 ContextFunction19 +ContextFunction19 ContextFunction20 +ContextFunction20 +ContextFunction21 ContextFunction21 ContextFunction22 +ContextFunction22 ContextFunction23 +ContextFunction23 +ContextFunction24 ContextFunction24 ContextFunction25 +ContextFunction25 ErasedFunction1 ErasedFunction2 ErasedFunction3 diff --git a/tests/run-macros/tasty-definitions-1/quoted_1.scala b/tests/run-macros/tasty-definitions-1/quoted_1.scala index 6ee80daeeb1d..11ed52f84265 100644 --- a/tests/run-macros/tasty-definitions-1/quoted_1.scala +++ b/tests/run-macros/tasty-definitions-1/quoted_1.scala @@ -60,6 +60,7 @@ object Macros { printout(defn.FunctionClass(i).name) for (i <- 0 to 25) + printout(defn.ContextFunctionClass(i).name) printout(defn.FunctionClass(i, isImplicit = true).name) for (i <- 1 to 25)