Skip to content

Commit d46235b

Browse files
committed
Fix "sbt console" in Scala 2 projects when sbt-dotty is in the build
See scala/scala-xml#313 for example. No test because apparently there's no way to properly test "sbt console" from scripted tests: https://github.com/sbt/sbt/blob/b6f02b9b8cd0abb15e3d8856fd76b570deb1bd61/sbt/src/sbt-test/project/console/test#L7
1 parent 9413cc0 commit d46235b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

sbt-dotty/src/dotty/tools/sbtplugin/DottyPlugin.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ object DottyPlugin extends AutoPlugin {
234234
// bootclasspath, and instead have scala-library and dotty-library on the
235235
// compiler classpath. This means that user code could shadow symbols
236236
// from these jars but we can live with that for now.
237+
238+
// sbt crazy scoping rules mean that when we override `classpathOptions`
239+
// below we also override `classpathOptions in console` which is normally
240+
// set in https://github.com/sbt/sbt/blob/b6f02b9b8cd0abb15e3d8856fd76b570deb1bd61/main/src/main/scala/sbt/Defaults.scala#L503,
241+
// this breaks `sbt console` in Scala 2 projects.
242+
// There seems to be no way to avoid stomping over task-scoped settings,
243+
// so we need to manually set `classpathOptions in console` to something sensible,
244+
// ideally this would be "whatever would be set if this plugin was not enabled",
245+
// but I can't find a way to do this, so we default to whatever is set in ThisBuild.
246+
classpathOptions in console := {
247+
if (isDotty.value)
248+
classpathOptions.value // The Dotty REPL doesn't require anything special on its classpath
249+
else
250+
(classpathOptions in console in ThisBuild).value
251+
},
237252
classpathOptions := {
238253
val old = classpathOptions.value
239254
if (isDotty.value)

0 commit comments

Comments
 (0)