When I define Wrapper as value class(extending AnyVal):
class Wrapper(val string: String) extends AnyVal
def wrapperHolder(w: Wrapper): {def wrapper: Wrapper} = new {
def wrapper: Wrapper = w
}
I have following compile error for wrapperHolder:
Error:(5, 22) Result type in structural refinement may not refer to a user-defined value class
def wrapper: Wrapper = w
- Why it doesn't work for value class?
Class.getMethod()
has no way to specify a Scala value class. However, this should not be an issue when it only appears as a result type. Perhaps the prohibition has the same origin, though, and Scala prohibits it more broadly than it needs to. – Shake