Skip to content

Commit 2c54a69

Browse files
committed
Fix "a pure expression does nothing" in synthetic REPL code
When you invoke repl with "-Wconf:any:error" currently you get ``` $line3.$read.INSTANCE.$iw ^ <synthetic>:6: error: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses (To diagnose errors in synthetic code, try adding `// show` to the end of your input.) ``` This fixes that by putting it into `val _`. I'm guessing this goes back all the way to 2006? (01443e4#diff-6eef86d28757da64bbaee0b568952750R332) but it's now surfaced.
1 parent b005ee7 commit 2c54a69

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/repl/scala/tools/nsc/interpreter/IMain.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ class IMain(val settings: Settings, parentClassLoaderOverride: Option[ClassLoade
923923
|object ${lineRep.evalName} {
924924
| ${if (resValSym != NoSymbol) s"lazy val ${lineRep.resultName} = ${originalPath(resValSym)}" else ""}
925925
| lazy val ${lineRep.printName}: _root_.java.lang.String = $executionWrapper {
926-
| $fullAccessPath
926+
| val _ = $fullAccessPath
927927
|""".stripMargin)
928928
if (contributors.lengthCompare(1) > 0) {
929929
code.println("val sb = new _root_.scala.StringBuilder")

test/files/run/repl-any-error.check

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
scala> 42
3+
val res0: Int = 42
4+
5+
scala> :quit

test/files/run/repl-any-error.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.tools.partest.ReplTest
2+
3+
object Test extends ReplTest {
4+
override def extraSettings = "-Wconf:any:error"
5+
6+
def code = """
7+
42
8+
""".trim
9+
}

test/files/run/t7747-repl.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ package $line10 {
266266
object $eval {
267267
lazy val $result = $line10.$read.INSTANCE.$iw.res3
268268
lazy val $print: _root_.java.lang.String = {
269-
$line10.$read.INSTANCE.$iw
269+
val _ = $line10.$read.INSTANCE.$iw
270270

271271
"" + "val res3: List[Product with java.io.Serializable]" + " = " + _root_.scala.runtime.ScalaRunTime.replStringOf($line10.$read.INSTANCE.$iw.res3, 1000)
272272

0 commit comments

Comments
 (0)