diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index f22523ac6f64..486005658d79 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -87,8 +87,21 @@ class ReplDriver(settings: Array[String], setupRootCtx(this.settings ++ settings, rootCtx) } + private val incompatibleOptions: Seq[String] = Seq( + initCtx.settings.YbestEffort.name, + initCtx.settings.YwithBestEffortTasty.name + ) + private def setupRootCtx(settings: Array[String], rootCtx: Context) = { - setup(settings, rootCtx) match + val incompatible = settings.intersect(incompatibleOptions) + val filteredSettings = + if !incompatible.isEmpty then + inContext(rootCtx) { + out.println(i"Options incompatible with repl will be ignored: ${incompatible.mkString(", ")}") + } + settings.filter(!incompatible.contains(_)) + else settings + setup(filteredSettings, rootCtx) match case Some((files, ictx)) => inContext(ictx) { shouldStart = true if files.nonEmpty then out.println(i"Ignoring spurious arguments: $files%, %") diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 67e63d0156a5..374f53dbd011 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -456,6 +456,17 @@ class ReplCompilerTests extends ReplTest: assertTrue(last, last.startsWith("val res0: tpolecat.type = null")) assertTrue(last, last.endsWith("""// result of "res0.toString" is null""")) + @Test def `i21431 filter out best effort options`: Unit = + initially: + run(":settings -Ybest-effort -Ywith-best-effort-tasty") + .andThen: + run("0") // check for crash + val last = lines() + println(last) + assertTrue(last(0), last(0) == ("Options incompatible with repl will be ignored: -Ybest-effort, -Ywith-best-effort-tasty")) + assertTrue(last(1), last(1) == ("val res0: Int = 0")) + + object ReplCompilerTests: private val pattern = Pattern.compile("\\r[\\n]?|\\n");