Ruggero Rossi created ZEPPELIN-658:
--------------------------------------
Summary: Scala: not accepting companion objects if defined in
different lines
Key: ZEPPELIN-658
URL: https://issues.apache.org/jira/browse/ZEPPELIN-658
Project: Zeppelin
Issue Type: Improvement
Affects Versions: 0.5.6
Environment: Linux Centos 7, Spark 1.6, Scala 2.10.6
Reporter: Ruggero Rossi
In Scala 2.10.x, a companion object must be in the same source file as the
related class, otherwise Scala will not accept it as a proper companion.
Now, it appears to me that Zeppelin sends every single line in a paragraph as a
separate line to the Scala REPL.
Doing so, it makes impossible for the companion object to be accepted.
I will make an example:. If I write in a Zeppelin paragraph:
// the case class
case class Person (var name: String, var age: Int)
// the companion object
object Person {
def apply() = new Person("<no name>", 0)
def apply(name: String) = new Person(name, 0)
}
I receive the following error:
warning: previously defined class Person is not a companion to object Person.
Companions must be defined together; you may wish to use :paste mode for this.
Now, if instead I paste everything on the same line, it works well:
case class Person (var name: String, var age: Int); object Person { def
apply() = new Person("<no name>", 0); def apply(name: String) = new
Person(name, 0); }
So it looks like this issue could be solved either by writing a text processor
that parses each line and paste them into a single line using semicolons in the
right places, or Zeppelin could just send the command “:paste” to the Scala
REPL (or have a setting that permits so).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)