Skip to content

Commit

Permalink
Ignore best effort settings in repl
Browse files Browse the repository at this point in the history
  • Loading branch information
jchyb committed Sep 4, 2024
1 parent 5e83606 commit 1e166cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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%, %")
Expand Down
11 changes: 11 additions & 0 deletions compiler/test/dotty/tools/repl/ReplCompilerTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 1e166cb

Please sign in to comment.