Maybe this was discussed before, sorry if I’m reviving an old topic …
In Scala 3 I was expecting custom
AnyVal types to be dropped / at least deprecated, due to the introduction of opaque type aliases.
AnyVal was introduced in SIP-15 with the purpose of having classes that “can get completely inlined, so operations on these classes have zero overhead compared to external methods”.
AnyVal has had serious limitations and bugs. I remember issues that were not fixed in Scala 2, because it’s too hard and because AnyVal is discouraged anyway. And now we have opaque types aliases, achievable in Scala 2 too, and which are better, superseding
AnyVal for the need of compile-time types.
AnyVal in its current form isn’t at least deprecated, I think we have 2 issues:
- How do we explain to beginners, or to ourselves, when to use
AnyValand when to use “opaque type aliases”?
- In Scala 2 there’s at least the use-case of defining zero-overhead extension methods, but that use-case is now gone too;
- What will happen when the JVM implements actual value types, whose semantics will probably be different?
- Are we hoping that we can modify the semantics of AnyVal to fit such value types?