Skip to content
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

Add reflect defn.FunctionClass overloads #16849

Merged
merged 1 commit into from
Feb 16, 2023
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
5 changes: 5 additions & 0 deletions compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2768,7 +2768,12 @@ 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 =
FunctionClass(arity, false, false)
def FunctionClass(arity: Int, isContextual: Boolean): Symbol =
FunctionClass(arity, isContextual, false)
def TupleClass(arity: Int): Symbol =
dotc.core.Symbols.defn.TupleType(arity).nn.classSymbol.asClass
def isTupleClass(sym: Symbol): Boolean =
Expand Down
19 changes: 19 additions & 0 deletions library/src/scala/quoted/Quotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4254,8 +4254,27 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
* - ...
* - Nth element is `FunctionN`
*/
// TODO: deprecate in 3.4 and stabilize FunctionClass(Int)/FunctionClass(Int,Boolean)
// @deprecated("Use overload of `FunctionClass` with 1 or 2 arguments","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.FunctionN` or `scala.ContextFunctionN`.
*
* @param arity the arity of the function where `0 <= arity`
* @param isContextual if it is a `scala.ContextFunctionN`
* @return class symbol of `scala.FunctionN` or `scala.ContextFunctionN` where `N == arity`
*/
@experimental
def FunctionClass(arity: Int, isContextual: Boolean): Symbol

/** Function-like object that maps arity to symbols for classes `scala.TupleX`.
* - 0th element is `NoSymbol`
* - 1st element is `NoSymbol`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ 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.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.
Expand Down
26 changes: 26 additions & 0 deletions tests/run-macros/tasty-definitions-1.check
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/run-macros/tasty-definitions-1/quoted_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ object Macros {
printout(defn.FunctionClass(i).name)

for (i <- 0 to 25)
printout(defn.FunctionClass(i, isContextual = true).name)
printout(defn.FunctionClass(i, isImplicit = true).name)

for (i <- 1 to 25)
Expand Down