Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-20706

Spark-shell not overriding method/variable definition

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0, 2.1.1, 2.2.0
    • Fix Version/s: 2.3.0
    • Component/s: Spark Shell
    • Labels:
      None
    • Environment:

      Linux, Scala 2.11.8

      Description

      !screenshot-1.png!In the following example, the definition of myMethod is not correctly updated:

      ------------------------------
      def myMethod() = "first definition"

      val tmp = myMethod(); val out = tmp

      println(out) // prints "first definition"

      def myMethod() = "second definition" // override above myMethod

      val tmp = myMethod(); val out = tmp

      println(out) // should be "second definition" but is "first definition"
      ------------------------------

      I'm using semicolon to force two statements to be compiled at the same time. It's also possible to reproduce the behavior using :paste

      So if I-redefine myMethod, the implementation seems not to be updated in this case. I figured out that the second-last statement (val out = tmp) causes this behavior, if this is moved in a separate block, the code works just fine.

      EDIT:

      The same behavior can be seen when declaring variables :

      ------------------------------
      val a = 1

      val b = a; val c = b;

      println(b) // prints "1"

      val a = 2 // override a

      val b = a; val c = b;

      println(b) // prints "1" instead of "2"
      ------------------------------

      Interestingly, if the second-last line "val b = a; val c = b;" is executed twice, then I get the expected result

        Attachments

        1. screenshot-1.png
          13 kB
          Raphael Roth

          Activity

            People

            • Assignee:
              mpetruska Mark Petruska
              Reporter:
              raphsen Raphael Roth
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: