Skip to content

Instantly share code, notes, and snippets.

@asflierl
Created July 17, 2018 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asflierl/c459547dd18aac65f01e6b63374a4247 to your computer and use it in GitHub Desktop.
Save asflierl/c459547dd18aac65f01e6b63374a4247 to your computer and use it in GitHub Desktop.
uhm....
Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162).
Type in expressions for evaluation. Or try :help.
scala> case class Meep(msb: Long, lsb: Long)
defined class Meep
scala> case class Moop(value: Meep) extends AnyVal
defined class Moop
scala> case class Whee(moop: Moop, whoop: String)
defined class Whee
scala> def f[A <: AnyVal { def value: Meep }](as: A*): Seq[Long] = as.map(_.value.msb)
f: [A <: AnyVal{def value: Meep}](as: A*)Seq[Long]
scala> f(Moop(Meep(1, 2)))
res0: Seq[Long] = ArrayBuffer(1)
scala> def g[A <: AnyVal { def value: Meep }](things: { def moop: A }*): Seq[Long] = things.map(_.moop.value.msb)
g: [A <: AnyVal{def value: Meep}](things: AnyRef{def moop: A}*)Seq[Long]
scala> g(Whee(Moop(Meep(1, 2)), "eh"))
java.lang.NoSuchMethodException: Meep.value()
at java.lang.Class.getMethod(Class.java:1786)
at .reflMethod$Method1(<console>:13)
at .$anonfun$g$1(<console>:13)
at .$anonfun$g$1$adapted(<console>:13)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
at scala.collection.TraversableLike.map(TraversableLike.scala:234)
at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at .g(<console>:13)
... 28 elided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment