Skip to content

Commit 7f787be

Browse files
committed
Stabilise Quotes reflect methods used for creating new classes/objects
1 parent a431d3a commit 7f787be

File tree

34 files changed

+18
-81
lines changed

34 files changed

+18
-81
lines changed

library/src/scala/quoted/Quotes.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
493493
* @param body List of members of the class. The members must align with the members of `cls`.
494494
*/
495495
// TODO add selfOpt: Option[ValDef]?
496-
@experimental def apply(cls: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): ClassDef
496+
// ^ if a use-case shows up, we add this via an overloaded method
497+
def apply(cls: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): ClassDef
497498
def copy(original: Tree)(name: String, constr: DefDef, parents: List[Tree /* Term | TypeTree */], selfOpt: Option[ValDef], body: List[Statement]): ClassDef
498499
def unapply(cdef: ClassDef): (String, DefDef, List[Tree /* Term | TypeTree */], Option[ValDef], List[Statement])
499500

@@ -518,7 +519,8 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
518519
* @syntax markdown
519520
*/
520521
// TODO add selfOpt: Option[ValDef]?
521-
@experimental def module(module: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): (ValDef, ClassDef)
522+
// ^ if a use-case shows up, we can add this via an overloaded method
523+
def module(module: Symbol, parents: List[Tree /* Term | TypeTree */], body: List[Statement]): (ValDef, ClassDef)
522524
}
523525

524526
/** Makes extension methods on `ClassDef` available without any imports */
@@ -3878,7 +3880,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
38783880
* @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be
38793881
* direct or indirect children of the reflection context's owner.
38803882
*/
3881-
@experimental def newClass(owner: Symbol, name: String, parents: List[TypeRepr], decls: Symbol => List[Symbol], selfType: Option[TypeRepr]): Symbol
3883+
def newClass(owner: Symbol, name: String, parents: List[TypeRepr], decls: Symbol => List[Symbol], selfType: Option[TypeRepr]): Symbol
38823884

38833885
/** Generates a new class symbol for a class with a public single term clause constructor.
38843886
*
@@ -3936,7 +3938,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
39363938
* @note As a macro can only splice code into the point at which it is expanded, all generated symbols must be
39373939
* direct or indirect children of the reflection context's owner.
39383940
*/
3939-
@experimental def newClass(
3941+
def newClass(
39403942
owner: Symbol,
39413943
name: String,
39423944
parents: Symbol => List[TypeRepr],
@@ -4038,7 +4040,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
40384040
*/
40394041
// Keep doc aligned with QuotesImpl's validFlags: `clsFlags` with `validClassFlags`, `conFlags` with `validClassConstructorFlags`,
40404042
// conParamFlags with `validClassTypeParamFlags` and `validClassTermParamFlags`
4041-
@experimental def newClass(
4043+
def newClass(
40424044
owner: Symbol,
40434045
name: String,
40444046
parents: Symbol => List[TypeRepr],
@@ -4110,7 +4112,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
41104112
*
41114113
* @syntax markdown
41124114
*/
4113-
@experimental def newModule(owner: Symbol, name: String, modFlags: Flags, clsFlags: Flags, parents: Symbol => List[TypeRepr], decls: Symbol => List[Symbol], privateWithin: Symbol): Symbol
4115+
def newModule(owner: Symbol, name: String, modFlags: Flags, clsFlags: Flags, parents: Symbol => List[TypeRepr], decls: Symbol => List[Symbol], privateWithin: Symbol): Symbol
41144116

41154117
/** Generates a new method symbol with the given parent, name and type.
41164118
*
@@ -4225,7 +4227,6 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
42254227
*
42264228
* @param prefix Prefix of the fresh name
42274229
*/
4228-
@experimental
42294230
def freshName(prefix: String): String
42304231
}
42314232

tests/neg-macros/i19842-a.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:210)
1212
| at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:286)
1313
| at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:285)
14-
| at Macros$.makeSerializer(Macro.scala:25)
14+
| at Macros$.makeSerializer(Macro.scala:23)
1515
|
1616
|---------------------------------------------------------------------------------------------------------------------
1717
|Inline stack trace

tests/neg-macros/i19842-a/Macro.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -experimental
2-
31
import scala.annotation.{experimental, targetName}
42
import scala.quoted.*
53
import scala.util.Try

tests/neg-macros/i19842-b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
| at dotty.tools.dotc.transform.TreeChecker$.checkParents(TreeChecker.scala:210)
1212
| at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:286)
1313
| at scala.quoted.runtime.impl.QuotesImpl$reflect$ClassDef$.module(QuotesImpl.scala:285)
14-
| at Macros$.makeSerializer(Macro.scala:27)
14+
| at Macros$.makeSerializer(Macro.scala:25)
1515
|
1616
|---------------------------------------------------------------------------------------------------------------------
1717
|Inline stack trace

tests/neg-macros/i19842-b/Macro.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -experimental
2-
31
import scala.annotation.{experimental, targetName}
42
import scala.quoted.*
53
import scala.util.Try

tests/neg-macros/newClassExtendsNoParents/Macro_1.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -experimental
2-
31
import scala.quoted.*
42

53
inline def makeClass(inline name: String): Any = ${ makeClassExpr('name) }
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//> using options -experimental
2-
31
def test: Any = makeClass("foo") // error

tests/neg-macros/newClassExtendsOnlyTrait/Macro_1.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//> using options -experimental
2-
31
import scala.quoted.*
42

53
inline def makeClass(inline name: String): Foo = ${ makeClassExpr('name) }
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//> using options -experimental
2-
31
def test: Foo = makeClass("foo") // error

tests/neg-macros/newClassParamsMissingArgument.check

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
-- Error: tests/neg-macros/newClassParamsMissingArgument/Test_2.scala:4:2 ----------------------------------------------
3-
4 | makeClass("foo") // error // error
2+
-- Error: tests/neg-macros/newClassParamsMissingArgument/Test_2.scala:2:2 ----------------------------------------------
3+
2 | makeClass("foo") // error // error
44
| ^^^^^^^^^^^^^^^^
55
|wrong number of arguments at inlining (while expanding macro) for (idx: Int): foo: (foo#<init> : (idx: Int): foo), expected: 1, found: 0
6-
-- Error: tests/neg-macros/newClassParamsMissingArgument/Test_2.scala:4:11 ---------------------------------------------
7-
4 | makeClass("foo") // error // error
6+
-- Error: tests/neg-macros/newClassParamsMissingArgument/Test_2.scala:2:11 ---------------------------------------------
7+
2 | makeClass("foo") // error // error
88
| ^^^^^^^^^^^^^^^^
99
|Malformed tree was found while expanding macro with -Xcheck-macros.
1010
|The tree does not conform to the compiler's tree invariants.
@@ -26,7 +26,7 @@
2626
|---------------------------------------------------------------------------------------------------------------------
2727
|Inline stack trace
2828
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29-
|This location contains code that was inlined from Macro_1.scala:5
30-
5 |inline def makeClass(inline name: String): Object = ${ makeClassExpr('name) }
29+
|This location contains code that was inlined from Macro_1.scala:3
30+
3 |inline def makeClass(inline name: String): Object = ${ makeClassExpr('name) }
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3232
---------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)