Skip to content

Commit b37e461

Browse files
committed
Add a Var abstraction in QuoteUtils
1 parent 0ebbcff commit b37e461

File tree

4 files changed

+725
-2
lines changed

4 files changed

+725
-2
lines changed

compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ class BootstrappedOnlyCompilationTests extends ParallelTesting {
120120
implicit val testGroup: TestGroup = TestGroup("runWithCompiler")
121121
aggregateTests(
122122
compileFilesInDir("tests/run-with-compiler", withCompilerOptions),
123-
compileDir("tests/run-with-compiler-custom-args/tasty-interpreter", withCompilerOptions),
124-
compileFile("tests/run-with-compiler-custom-args/staged-streams_1.scala", withCompilerOptions without "-Yno-deep-subtypes")
123+
compileDir("tests/run-with-compiler-custom-args/tasty-interpreter", withCompilerOptions)
125124
).checkRuns()
126125
}
127126

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package scala.quoted
2+
package util
3+
4+
/** An abstraction for variable definition to use in a quoted program.
5+
* It decouples the operations of get and update, if needed to be spliced separately.
6+
*/
7+
sealed trait Var[T] {
8+
def get given QuoteContext: Expr[T]
9+
def update(x: Expr[T]) given QuoteContext: Expr[Unit]
10+
}
11+
12+
object Var {
13+
def apply[T: Type, U: Type](init: Expr[T])(body: Var[T] => Expr[U]) given QuoteContext: Expr[U] = '{
14+
var x = $init
15+
${
16+
body(
17+
new Var[T] {
18+
def get given QuoteContext: Expr[T] = 'x
19+
def update(e: Expr[T]) given QuoteContext: Expr[Unit] = '{ x = $e }
20+
}
21+
)
22+
}
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
6
2+
3+
12
4+
5+
36
6+
7+
2
8+
9+
3
10+
11+
7
12+
13+
12
14+
15+
15
16+
17+
15
18+
19+
72

0 commit comments

Comments
 (0)