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 11package dotty .tools .dotc .quoted
22
33import dotty .tools .dotc .Driver
4- import dotty .tools .dotc .core .Contexts .Context
4+ import dotty .tools .dotc .core .Contexts .{ Context , FreshContext }
55import dotty .tools .dotc .core .StdNames ._
66import dotty .tools .io .VirtualDirectory
7-
87import dotty .tools .repl .AbstractFileClassLoader
98
109import scala .quoted .Expr
11-
1210import java .io .ByteArrayOutputStream
1311import java .io .PrintStream
1412import java .nio .charset .StandardCharsets
Original file line number Diff line number Diff line change 11package dotty .tools .dotc .quoted
22
3+ import dotty .tools .dotc .ast .Trees .Literal
4+ import dotty .tools .dotc .core .Constants .Constant
5+ import dotty .tools .dotc .printing .RefinedPrinter
6+
37import scala .quoted .Expr
48import scala .quoted .Liftable .ConstantExpr
59import scala .runtime .quoted ._
@@ -15,7 +19,11 @@ object Runners {
1519 }
1620
1721 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 )
1927 case _ => new QuoteDriver ().show(expr)
2028 }
2129 }
Original file line number Diff line number Diff line change @@ -198,6 +198,7 @@ class CompilationTests extends ParallelTesting {
198198 implicit val testGroup : TestGroup = TestGroup (" runAll" )
199199 compileFilesInDir(" ../tests/run" , defaultOptions) +
200200 compileFilesInDir(" ../tests/run-no-optimise" , defaultOptions) +
201+ compileFile(" ../tests/run-special/quote-run-constants.scala" , defaultRunWithCompilerOptions) +
201202 compileFile(" ../tests/run-special/quote-run.scala" , defaultRunWithCompilerOptions) +
202203 compileFile(" ../tests/run-special/quote-run-2.scala" , defaultRunWithCompilerOptions) +
203204 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