Ammonite icon indicating copy to clipboard operation
Ammonite copied to clipboard

Value class support in class-based mode?

Open vreuter opened this issue 4 years ago • 1 comments

It seems I'm unable to write a value class when in class-based mode, but without --class-based it works. This looks true both for my version with Scala 2.13...

$ amm
Loading...
Welcome to the Ammonite Repl 2.3.8 (Scala 2.13.3 Java 11.0.9)
@ class Name(val value: String) extends AnyVal 
defined class Name

@ exit 
Bye!
$ amm --class-based
Loading...
Welcome to the Ammonite Repl 2.3.8 (Scala 2.13.3 Java 11.0.9)
@ class Name(val value: String) extends AnyVal 
cmd0.sc:1: value class may not be a member of another class
class Name(val value: String) extends AnyVal
      ^
Compilation Failed

@  

...and with Scala 2.12...

$ amm212
Loading...
Welcome to the Ammonite Repl 2.3.8-36-1cce53f3 (Scala 2.12.13 Java 11.0.9)
@ class Name(val value: String) extends AnyVal 
defined class Name

@ exit 
Bye!
$ amm212 --class-based
Loading...
Welcome to the Ammonite Repl 2.3.8-36-1cce53f3 (Scala 2.12.13 Java 11.0.9)
@ class Name(val value: String) extends AnyVal 
cmd0.sc:1: value class may not be a member of another class
class Name(val value: String) extends AnyVal
      ^
Compilation Failed

@  

Searching around, it looks like this was an issue that came up in the normal REPL and was addressed. Was something similar done here in Ammonite and I'm missing something, or is this actually an issue?

vreuter avatar Mar 12 '21 22:03 vreuter

It wasn't fixed in scala repl. It just fallback to object wrapper when value classes are defined: https://github.com/scala/scala/commit/fd6ea5b137de04756ea7514a4504bce83c235bb1

scalway avatar Apr 04 '21 12:04 scalway