Skip to content

Commit eb8a315

Browse files
committed
Ignore best effort settings in repl
1 parent 7d12783 commit eb8a315

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,21 @@ class ReplDriver(settings: Array[String],
8787
setupRootCtx(this.settings ++ settings, rootCtx)
8888
}
8989

90+
private val incompatibleOptions: Seq[String] = Seq(
91+
initCtx.settings.YbestEffort.name,
92+
initCtx.settings.YwithBestEffortTasty.name
93+
)
94+
9095
private def setupRootCtx(settings: Array[String], rootCtx: Context) = {
91-
setup(settings, rootCtx) match
96+
val incompatible = settings.intersect(incompatibleOptions)
97+
val filteredSettings =
98+
if !incompatible.isEmpty then
99+
inContext(rootCtx) {
100+
out.println(i"Options incompatible with repl will be ignored: ${incompatible.mkString(", ")}")
101+
}
102+
settings.filter(!incompatible.contains(_))
103+
else settings
104+
setup(filteredSettings, rootCtx) match
92105
case Some((files, ictx)) => inContext(ictx) {
93106
shouldStart = true
94107
if files.nonEmpty then out.println(i"Ignoring spurious arguments: $files%, %")

compiler/test/dotty/tools/repl/ReplCompilerTests.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,17 @@ class ReplCompilerTests extends ReplTest:
456456
assertTrue(last, last.startsWith("val res0: tpolecat.type = null"))
457457
assertTrue(last, last.endsWith("""// result of "res0.toString" is null"""))
458458

459+
@Test def `i21431 filter out best effort options`: Unit =
460+
initially:
461+
run(":settings -Ybest-effort -Ywith-best-effort-tasty")
462+
.andThen:
463+
run("0") // check for crash
464+
val last = lines()
465+
println(last)
466+
assertTrue(last(0), last(0) == ("Options incompatible with repl will be ignored: -Ybest-effort, -Ywith-best-effort-tasty"))
467+
assertTrue(last(1), last(1) == ("val res0: Int = 0"))
468+
469+
459470
object ReplCompilerTests:
460471

461472
private val pattern = Pattern.compile("\\r[\\n]?|\\n");

0 commit comments

Comments
 (0)