Closed
Description
Dotty REPL looks treating show
method specially to show the result of an instance creation.
In 0.2.0-RC1, a class or a trait which has show()
method cannot be instantiated as follows.
(show
without parenthesis or show(msg:String)
does compile, but unexpectedly used to show the result of instantiation. However, it doesn't change toString
implementation.)
scala> class A
defined class A
scala> new A()
val res0: A = A@7ee936b9
scala> class B{def show() = "hello"}
defined class B
scala> new B()
-- Error: <console>:8:34 -------------------------------------------------------
8 | line4$object.$iw.$iw.`res1`.show /*toString()*/ + "\n"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| missing arguments for method show in class B
scala> class C{def show = "hello"}
defined class C
scala> new C()
val res2: C = hello
scala> class D{def show(msg:String) = msg}
defined class D
scala> new D()
val res3: D = RequestResult$$$Lambda$2438/163387956@1cf3be8e
scala> new D().toString
val res4: String = "D@3b3354b5"
scala> trait E{def show() = "hello"}
defined trait E
scala> new E{}
-- Error: <console>:8:35 -------------------------------------------------------
8 | line12$object.$iw.$iw.`res6`.show /*toString()*/ + "\n"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| missing arguments for method show in trait E
In 0.1.2-RC1, it behaves similar but a bit different.
A class or a trait which has show
with arguments cannot be instantiated as follows.
(show
without parenthesis or show()
does compile, but unexpectedly used to show the result of instantiation. However, it doesn't change toString
implementation.)
scala> class A
defined class A
scala> new A()
val res0: A = A@6916f3d3
scala> class B{def show() = "hello"}
defined class B
scala> new B()
val res1: B = hello
scala> class C{def show = "hello")
-- [E039] Syntax Error: <console>:1:26 -----------------------------------------
1 |class C{def show = "hello")
| ^
| ';' expected, but ')' found
scala> class C{def show = "hello"}
defined class C
scala> new C()
val res2: C = hello
scala> class D{def show(msg:String) = msg}
defined class D
scala> new D()
-- Error: <console>:8:34 -------------------------------------------------------
8 | line8$object.$iw.$iw.`res3`.show /*toString()*/ + "\n"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|missing arguments for method show in class D
|follow this method with `_' if you want to treat it as a partially applied function
scala> new C().toString
val res4: String = "C@772abeb"
scala> trait E{def show(msg:String) = msg}
defined trait E
scala> new E{}
-- Error: <console>:8:35 -------------------------------------------------------
8 | line13$object.$iw.$iw.`res5`.show /*toString()*/ + "\n"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|missing arguments for method show in trait E
|follow this method with `_' if you want to treat it as a partially applied function
scala> class F{def show(i:Int) = i}
defined class F
scala> new F()
-- Error: <console>:8:35 -------------------------------------------------------
8 | line15$object.$iw.$iw.`res6`.show /*toString()*/ + "\n"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|missing arguments for method show in class F
|follow this method with `_' if you want to treat it as a partially applied function
Metadata
Metadata
Assignees
Labels
No labels