Skip to content

Commit e0a5bb6

Browse files
committed
Allow only select flags, add test and fix CI issues
1 parent 04a11ce commit e0a5bb6

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
370370
(vdef.name.toString, vdef.tpt, optional(vdef.rhs))
371371

372372
def let(owner: Symbol, name: String, rhs: Term, flags: Flags)(body: Ref => Term): Term =
373-
Symbol.checkValidFlags(flags.toTermFlags, Flags.validValFlags)
373+
Symbol.checkValidFlags(flags.toTermFlags, Flags.validValInLetFlags)
374374
val vdef = tpd.SyntheticValDef(name.toTermName, rhs, flags)(using ctx.withOwner(owner))
375375
val ref = tpd.ref(vdef.symbol).asInstanceOf[Ref]
376376
Block(List(vdef), body(ref))
@@ -3256,7 +3256,8 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
32563256
private[QuotesImpl] def validMethodFlags: Flags = Private | Protected | Override | Deferred | Final | Method | Implicit | Given | Local | AbsOverride | JavaStatic | Synthetic | Artifact // Flags that could be allowed: Synthetic | ExtensionMethod | Exported | Erased | Infix | Invisible
32573257
// Keep: aligned with Quotes's `newVal` doc
32583258
private[QuotesImpl] def validValFlags: Flags = Private | Protected | Override | Deferred | Final | Param | Implicit | Lazy | Mutable | Local | ParamAccessor | Module | Package | Case | CaseAccessor | Given | Enum | AbsOverride | JavaStatic | Synthetic | Artifact // Flags that could be added: Synthetic | Erased | Invisible
3259-
3259+
// Keep: aligned with Quotes's `let` doc
3260+
private[QuotesImpl] def validValInLetFlags: Flags = Final | Implicit | Lazy | Mutable | Given | Synthetic
32603261
// Keep: aligned with Quotes's `newBind` doc
32613262
private[QuotesImpl] def validBindFlags: Flags = Case // Flags that could be allowed: Implicit | Given | Erased
32623263

library/src/scala/quoted/Quotes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,9 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
693693
* }
694694
* ```
695695
*
696-
* @param flags extra flags to with which the symbol should be constructed. Can be `Private | Protected | Override | Deferred | Final | Param | Implicit | Lazy | Mutable | Local | ParamAccessor | Module | Package | Case | CaseAccessor | Given | Enum | JavaStatic | Synthetic | Artifact`
696+
* @param flags extra flags to with which the symbol should be constructed. Can be `Final | Implicit | Lazy | Mutable | Given | Synthetic`
697697
*/
698-
// Keep: `flags` doc aligned with QuotesImpl's `validValFlags`
698+
// Keep: `flags` doc aligned with QuotesImpl's `validValInLetFlags`
699699
def let(owner: Symbol, name: String, rhs: Term, flags: Flags)(body: Ref => Term): Term
700700

701701
/** Creates a block `{ val <name> = <rhs: Term>; <body(x): Term> }`

project/MiMaFilters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ object MiMaFilters {
2525

2626
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.stableNull"),
2727

28-
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#ValDefModule.let"),
2928
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.quoted.Quotes#reflectModule#ValDefModule.let"),
3029
),
3130

@@ -132,6 +131,7 @@ object MiMaFilters {
132131
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeMethods.methodTypeKind"),
133132
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#MethodTypeMethods.isContextual"),
134133
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#ImplicitsModule.searchIgnoring"),
134+
ProblemFilters.exclude[ReversedMissingMethodProblem]("scala.quoted.Quotes#reflectModule#ValDefModule.let"),
135135
// Change `experimental` annotation to a final class
136136
ProblemFilters.exclude[FinalClassProblem]("scala.annotation.experimental"),
137137
),

tests/neg-macros/i23008.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
| Exception occurred while executing macro expansion.
66
| java.lang.IllegalArgumentException: requirement failed: value of StringConstant cannot be `null`
77
| at scala.Predef$.require(Predef.scala:337)
8-
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2534)
9-
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2533)
8+
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2540)
9+
| at scala.quoted.runtime.impl.QuotesImpl$reflect$StringConstant$.apply(QuotesImpl.scala:2539)
1010
| at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:80)
1111
| at scala.quoted.ToExpr$StringToExpr.apply(ToExpr.scala:78)
1212
| at scala.quoted.Expr$.apply(Expr.scala:70)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x: 1, y: string
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import scala.quoted._
2+
3+
object Macro:
4+
inline def makeBlock(): Unit = ${makeBlockImpl}
5+
def makeBlockImpl(using Quotes): Expr[Unit] = {
6+
import quotes.reflect._
7+
ValDef.let(Symbol.spliceOwner, "x", '{0}.asTerm, Flags.Mutable) { x =>
8+
ValDef.let(Symbol.spliceOwner, "y", '{"string"}.asTerm, Flags.Lazy) { y =>
9+
'{
10+
${Assign(x, '{1}.asTerm).asExpr}
11+
println("x: " + ${x.asExprOf[Int]} + ", y: " + ${y.asExprOf[String]})
12+
}.asTerm
13+
}
14+
}.asExprOf[Unit]
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@main def Test = Macro.makeBlock()

0 commit comments

Comments
 (0)