File tree Expand file tree Collapse file tree 5 files changed +81
-4
lines changed
src/dotty/tools/dotc/quoted Expand file tree Collapse file tree 5 files changed +81
-4
lines changed Original file line number Diff line number Diff line change 1
1
package dotty .tools .dotc .quoted
2
2
3
3
import dotty .tools .dotc .Driver
4
- import dotty .tools .dotc .core .Contexts .Context
4
+ import dotty .tools .dotc .core .Contexts .{ Context , FreshContext }
5
5
import dotty .tools .dotc .core .StdNames ._
6
6
import dotty .tools .io .VirtualDirectory
7
-
8
7
import dotty .tools .repl .AbstractFileClassLoader
9
8
10
9
import scala .quoted .Expr
11
-
12
10
import java .io .ByteArrayOutputStream
13
11
import java .io .PrintStream
14
12
import java .nio .charset .StandardCharsets
Original file line number Diff line number Diff line change 1
1
package dotty .tools .dotc .quoted
2
2
3
+ import dotty .tools .dotc .ast .Trees .Literal
4
+ import dotty .tools .dotc .core .Constants .Constant
5
+ import dotty .tools .dotc .printing .RefinedPrinter
6
+
3
7
import scala .quoted .Expr
4
8
import scala .quoted .Liftable .ConstantExpr
5
9
import scala .runtime .quoted ._
@@ -15,7 +19,11 @@ object Runners {
15
19
}
16
20
17
21
def show (expr : Expr [T ]): String = expr match {
18
- case expr : ConstantExpr [T ] => expr.value.toString
22
+ case expr : ConstantExpr [T ] =>
23
+ val ctx = new QuoteDriver ().initCtx
24
+ ctx.settings.color.update(" never" )(ctx)
25
+ val printer = new RefinedPrinter (ctx)
26
+ printer.toText(Literal (Constant (expr.value))).mkString(Int .MaxValue , false )
19
27
case _ => new QuoteDriver ().show(expr)
20
28
}
21
29
}
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ class CompilationTests extends ParallelTesting {
195
195
implicit val testGroup : TestGroup = TestGroup (" runAll" )
196
196
compileFilesInDir(" ../tests/run" , defaultOptions) +
197
197
compileFilesInDir(" ../tests/run-no-optimise" , defaultOptions) +
198
+ compileFile(" ../tests/run-special/quote-run-constants.scala" , defaultRunWithCompilerOptions) +
198
199
compileFile(" ../tests/run-special/quote-run.scala" , defaultRunWithCompilerOptions) +
199
200
compileFile(" ../tests/run-special/quote-run-2.scala" , defaultRunWithCompilerOptions) +
200
201
compileFile(" ../tests/run-special/quote-run-staged-interpreter.scala" , defaultRunWithCompilerOptions)
Original file line number Diff line number Diff line change
1
+ true
2
+ a
3
+
4
+
5
+ "
6
+ '
7
+ \
8
+ 1
9
+ 2
10
+ 3
11
+ 4.0
12
+ 5.0
13
+ xyz
14
+ ======
15
+ true
16
+ 'a'
17
+ '\n'
18
+ '\"'
19
+ '\''
20
+ '\\'
21
+ 1
22
+ 2
23
+ 3L
24
+ 4.0
25
+ 5.0
26
+ "xyz"
27
+ "\n\\\"\'"
28
+ "abc\n xyz"
Original file line number Diff line number Diff line change
1
+
2
+ import dotty .tools .dotc .quoted .Runners ._
3
+
4
+ import scala .quoted ._
5
+
6
+ object Test {
7
+ def main (args : Array [String ]): Unit = {
8
+ def run [T ](expr : Expr [T ]): Unit = println(expr.run)
9
+ def show [T ](expr : Expr [T ]): Unit = println(expr.show)
10
+
11
+ run(true )
12
+ run('a' )
13
+ run('\n ' )
14
+ run('"' )
15
+ run('\' ' )
16
+ run('\\ ' )
17
+ run(1 )
18
+ run(2 )
19
+ run(3L )
20
+ run(4.0f )
21
+ run(5.0d )
22
+ run(" xyz" )
23
+
24
+ println(" ======" )
25
+
26
+ show(true )
27
+ show('a' )
28
+ show('\n ' )
29
+ show('"' )
30
+ show('\' ' )
31
+ show('\\ ' )
32
+ show(1 )
33
+ show(2 )
34
+ show(3L )
35
+ show(4.0f )
36
+ show(5.0d )
37
+ show(" xyz" )
38
+ show(" \n\\\" '" )
39
+ show(""" abc
40
+ xyz""" )
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments