2
votes

Using : Scala 2.10.3

Trying to compile the following gives an error. If I remove the case-class then it compiles.

Anythoughts on where the double is being resolved from?

object DomainTypes {
type Tagged[T] = { type Tag = T }
trait DeviceIdTag
type DeviceId = Int with Tagged[DeviceIdTag]

implicit class TaggedInt(val data: Int) extends AnyVal {

 def deviceId = {
  require(data >= 1)
  data.asInstanceOf[DeviceId]
}
}
}

 case class DeviceIdHolder(odeviceId:DeviceId)

[error] type mismatch; [error] found : Double [error] required: AnyRef [error] Note: an implicit exists from scala.Double => java.lang.Double, but [error] methods inherited from Object are rendered ambiguous. This is to avoid [error] a blanket implicit which would convert any scala.Double to any AnyRef. [error] You may wish to use a type ascription: x: java.lang.Double. [error] one error found [error] (compile:compile) Compilation failed [error] Total time: 0 s, completed Mar 2, 2014 11:47:01 AM

If you replace the INT's with String's then it compiles, so I don't think there is anything structurally wrong per-se.

1
What release version of scala are you using?C R
Updated with version. It's probably related to this : stackoverflow.com/questions/20094679/…bearrito
The message is potentially more helpful under 2.11.som-snytt

1 Answers

1
votes

The correct answer is found here : https://stackoverflow.com/a/21285738/386159.

Ideally, an editor would mark this as a duplicate and point to the question to which I have linked.