diff options
author | nilday <howard.h.l@126.com> | 2016-09-16 17:25:25 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:39 -0500 |
commit | c89f87c9c9a0c7b256f225e37c55cb34f060aa6c (patch) | |
tree | d24a5ebc3c10a5a621885297aa957980a482e388 /libraries | |
parent | d89c9bdd16c7be729383acf438fcde4cdd863e9c (diff) | |
download | cbt-c89f87c9c9a0c7b256f225e37c55cb34f060aa6c.tar.gz cbt-c89f87c9c9a0c7b256f225e37c55cb34f060aa6c.tar.bz2 cbt-c89f87c9c9a0c7b256f225e37c55cb34f060aa6c.zip |
util-eval: Reset reporter while apply compiling
Problem
I notice that the former release 6.36.0 reset the reporter after
check(), which is not enough. In my use case, I would like to use
apply with resetState=false (or simply inPlace), without checking
it before (check method requires compiling every time, but apply
method has cache).
Under such circumstance, if I offer a piece of code with syntax
error, it will throw CompilerException every time even if I
correct it. It’s because the reporter hasn’t been reset.
Solution
Simply add resetReporter before compile will solve the problem.
Signed-off-by: Christopher Coco <ccoco@twitter.com>
RB_ID=871408
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/eval/Eval.scala | 3 | ||||
-rw-r--r-- | libraries/eval/test/EvalTest.scala | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index abd1836..1ab5762 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -581,6 +581,9 @@ class Eval(target: Option[File]) { if (Debug.enabled) Debug.printWithLineNumbers(code) + //reset reporter, or will always throw exception after one error while resetState==false + resetReporter() + // if you're looking for the performance hit, it's 1/2 this line... val compiler = new global.Run val sourceFiles = List(new BatchSourceFile("(inline)", code)) diff --git a/libraries/eval/test/EvalTest.scala b/libraries/eval/test/EvalTest.scala index 8b986e2..d445424 100644 --- a/libraries/eval/test/EvalTest.scala +++ b/libraries/eval/test/EvalTest.scala @@ -217,6 +217,18 @@ class EvalTest extends WordSpec { assert(eval.errors.isEmpty) } + "reset reporter between inPlace invocations" in { + val ctx = new Ctx + import ctx._ + + intercept[Throwable] { + eval.inPlace[Int]("val a = 3; val b = q; a + b") + } + assert(eval.errors.nonEmpty) + assert(eval.inPlace[Int]("val d = 3; val e = 2; d + e") == 5) + assert(eval.errors.isEmpty) + } + "reporter should be reset between checks, but loaded class should remain" in { val ctx = new Ctx import ctx._ |