If we are working with these types:
class Meter(val toDouble: Double) extends AnyVal
class IntOps(val toInt: Int) extends NewType
class MeterOps(val toMeter: Meter) extends NewType
Then I’d answer your questions as follows:
- Primitives would have to box in their usual cases. So
IntOps
boxes toInteger
in exactly the cases thatInt
does (and usesint
otherwise). - I think that we’d want to erase newtypes before any of the
AnyVal
rewrites occur. So, we’d potentially have newtype forwarders (essentially static methods taking the underlying type), as well as the wholeAnyVal
system of forwarders and boxing. SoMeterOps
would be allowed, and values of that type would be represented identically toMeter
at runtime. -
isInstanceOf[IntOps]
could be rewritten toisInstanceOf[Int]
or an error. Probably the rewrite makes more sense. Similarly,IntOps
could be forbidden in pattern matches, or rewritten toInt
. - I’m pretty sure we’d want to rewrite
classOf[IntOps]
andclassTag[IntOps]
to useInt
. -
Array[IntOps]
would be represented asArray[Int]
. - At runtime there are no values of
IntOps
type, so I don’t think there are special considerations here.
A SIP would require a better formal specification, but I think these are the right properties to want.