New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A var defined in a script not updated after reload in REPL with -Yrepl-class-based #9740

Closed
scabug opened this Issue Apr 6, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Apr 6, 2016

It is possible to produce this problem with the Scala REPL using -Yrepl-class-based. The key to triggering this problem seems to be having an anonymous class with at least two members. Included is a new sample file that can be used to exhibit this problem. Below is a session showing the behavior:

~/t/t/6393 scala -Yrepl-class-based
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_74).
Type in expressions for evaluation. Or try :help.

scala> :load Fail.scala
Loading Fail.scala...
X: Serializable{def getArray(n: Int): Array[Double]; def multiplySum(x: Double,v: Seq[Double]): Double} = $anon$1@5ddf0d24

scala> val a = X.getArray(100)
warning: there was one feature warning; re-run with -feature for details
a: Array[Double] = Array(0.6445967025789217, 0.8356433165638456, 0.9050186287112574, 0.06344554850936357, 0.008363070900988756, 0.6593626537474886, 0.7424265307039932, 0.5035629973234215, 0.5510831160354674, 0.37366654438205593, 0.33299751842582703, 0.3800633883472283, 0.4153963387304084, 0.2752468331316783, 0.8699452196820426, 0.31938530945559984, 0.7990568815957724, 0.6875841747139724, 0.31949965197609675, 0.026911873556428878, 0.2616536698127736, 0.5580118021155783, 0.28345994848845435, 0.1773433165304532, 0.2549417030032525, 0.9777692443616465, 0.6296846343712603, 0.8589339648876033, 0.7020098253707141, 0.8518829567943531, 0.41154622619731374, 0.1075129613308311, 0.8499252434316056, 0.3841876768177086, 0.137415801614582, 0.27030938222499756, 0.5511585560527115, 0.26252884257087217, ...
scala> X = null
X: Serializable{def getArray(n: Int): Array[Double]; def multiplySum(x: Double,v: Seq[Double]): Double} = null

scala> :load Fail.scala
Loading Fail.scala...
X: Serializable{def getArray(n: Int): Array[Double]; def multiplySum(x: Double,v: Seq[Double]): Double} = $anon$1@52c8295b

scala> X
res0: Serializable{def getArray(n: Int): Array[Double]; def multiplySum(x: Double,v: Seq[Double]): Double} = null

This has been tested with Scala 2.11.8 and 2.11.7

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 6, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9740?orig=1
Reporter: Jim Powers (corruptmemory)
Affected Versions: 2.11.7, 2.11.8
Other Milestones: 2.12.0-M5
Attachments:

  • Fail.scala (created on Apr 6, 2016 5:21:50 PM UTC, 281 bytes)
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 6, 2016

@szeiger said:
Smaller reproduction: Fail.scala:

var X = new { 
  def x = Seq.empty[AnyRef].reduce((a,b) => a)
}

Script:

scala -nc -Yrepl-class-based
:load Fail.scala
val a = X
X = null
:load Fail.scala
X
:q
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 7, 2016

Jim Powers (corruptmemory) said:
Right. I forgot to include the information Iulian figured out. The problem is the a.

If you update the script to:

{noformat}scala -nc -Yrepl-class-based
:load Fail.scala
val aaa = X
X = null
:load Fail.scala
X
:q
{noformat}

You'll see that X updates properly.

So, the a in the def x = Seq.empty[AnyRef].reduce((a,b) => a) and the top-level a in the REPL seems to trigger the problem.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 7, 2016

@som-snytt said (edited on Apr 7, 2016 11:01:03 PM UTC):
Or

scala> var f: Int => Int = i => i
f: Int => Int = <function1>

scala> val i = f(10)
i: Int = 10

scala> f = null
f: Int => Int = null

scala> var f: Int => Int = i => i
f: Int => Int = <function1>

scala> f   // reports the first f, not its redefinition
res0: Int => Int = null

Both object and class templates (incorrectly or spuriously) import too much (both first f and i), but object template correctly imports the desired f, which hides the previous f. The class template has different logic that fails to import the correct f at res0, so it resolves to the incorrect one.

Imports can require previous imports:

scala> trait T ; class C { implicit val t: T = new T {} }
defined trait T
defined class C

scala> val c = new C
c: C = C@77afea7d

scala> import c.t
import c.t

scala> implicitly[T]
res0: T = C$$anon$1@5442a311

scala> val t = 17
t: Int = 17

scala> t
res1: T = C$$anon$1@5442a311
@scabug

This comment has been minimized.

Copy link
Author

scabug commented Apr 8, 2016

@scabug scabug closed this May 11, 2016

@scabug scabug added this to the 2.11.9 milestone Apr 7, 2017

ghost pushed a commit to dbtsai/spark that referenced this issue Dec 6, 2017

[SPARK-20706][SPARK-SHELL] Spark-shell not overriding method/variable…
… definition

## What changes were proposed in this pull request?

[SPARK-20706](https://issues.apache.org/jira/browse/SPARK-20706): Spark-shell not overriding method/variable definition
This is a Scala repl bug ( [SI-9740](scala/bug#9740) ), was fixed in version 2.11.9 ( [see the original PR](scala/scala#5090) )

## How was this patch tested?

Added a new test case in `ReplSuite`.

Author: Mark Petruska <petruska.mark@gmail.com>

Closes apache#19879 from mpetruska/SPARK-20706.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment