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
IntOpsboxes toIntegerin exactly the cases thatIntdoes (and usesintotherwise). - I think that we’d want to erase newtypes before any of the
AnyValrewrites occur. So, we’d potentially have newtype forwarders (essentially static methods taking the underlying type), as well as the wholeAnyValsystem of forwarders and boxing. SoMeterOpswould be allowed, and values of that type would be represented identically toMeterat runtime. -
isInstanceOf[IntOps]could be rewritten toisInstanceOf[Int]or an error. Probably the rewrite makes more sense. Similarly,IntOpscould 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
IntOpstype, 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.