From 95e270bb0df2d4eb643620627c3c222082fa763c Mon Sep 17 00:00:00 2001 From: Konrad Najder Date: Fri, 29 Dec 2023 12:34:19 +0100 Subject: [PATCH 1/2] Added a test for invalid literal breaking the compiler Whenever a non-compilable expression is the first thing evaluated after the Scala Compiler is created, all further expressions fail with a `scala.reflect.internal.FatalError: package scala does not have a member Nil` --- .../scex/compiler/InvalidLiteralTest.scala | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala diff --git a/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala b/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala new file mode 100644 index 0000000..e4f0a0f --- /dev/null +++ b/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala @@ -0,0 +1,22 @@ +package com.avsystem.scex.compiler + +import com.avsystem.scex.compiler.ScexCompiler.CompilationFailedException +import com.avsystem.scex.japi.{DefaultJavaScexCompiler, JavaScexCompiler} +import org.scalatest.funsuite.AnyFunSuite + +class InvalidLiteralTest extends AnyFunSuite with CompilationTest { + override protected def createCompiler: JavaScexCompiler = { + val settings = new ScexSettings + settings.classfileDirectory.value = "testClassfileCache" + //evaluating getter adapters fixes the problem (since the invalid expression isn't the first thing compiled) + settings.noGetterAdapters.value = true + new DefaultJavaScexCompiler(settings) + } + + test("Invalid literal should not break the scex compiler") { + intercept[CompilationFailedException] { + evaluate[String]("11compilation_fail11") + } + assert("ok" == evaluate[String]("\"ok\"")) + } +} From 4543c625ac35f7d728f6946a9d6003d47d3f5081 Mon Sep 17 00:00:00 2001 From: Konrad Najder Date: Fri, 29 Dec 2023 12:37:12 +0100 Subject: [PATCH 2/2] Simplified the test for invalid literal --- .../scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala b/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala index e4f0a0f..1d2b3ff 100644 --- a/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala +++ b/scex-core/src/test/scala/com/avsystem/scex/compiler/InvalidLiteralTest.scala @@ -17,6 +17,6 @@ class InvalidLiteralTest extends AnyFunSuite with CompilationTest { intercept[CompilationFailedException] { evaluate[String]("11compilation_fail11") } - assert("ok" == evaluate[String]("\"ok\"")) + evaluate[Unit]("()") } }