Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's clue: </p> <pre><code>scala&gt; val fooOpt: Option[Bar] = Option(Foo(1)) fooOpt: Option[Bar] = Some(Bar(1)) </code></pre> <p>And another:</p> <pre><code>scala&gt; implicit def foobar(x: String): Int = augmentString(x).toInt foobar: (x: String)Int scala&gt; val y: Option[String] = Option(1) y: Option[String] = Some(1) scala&gt; val y: Option[Int] = Option("1") y: Option[Int] = Some(1) </code></pre> <p>Looks like a legitimately <em>odd</em> bug. I'd pop open a smaller test case and open an issue (or search for one in JIRA).</p> <p>As an aside:</p> <p>You could use some category theory to handle lots of different types of "Option-ish" things.</p> <pre><code>package object fun { trait Functor[Container[_]] { def fmap[A,B](x: Container[A], f: A =&gt; B): Container[B] } object Functor { implicit object optionFunctor extends Functor[Option] { override def fmap[A,B](x: Option[A], f: A =&gt; B): Option[B] = x map f } // Note: With some CanBuildFrom magic, we can support Traversables here. } implicit def liftConversion[F[_], A, B](x: F[A])(implicit f: A =&gt; B, functor: Functor[F]): F[B] = functor.fmap(x,f) } </code></pre> <p>That's a bit more advanced, as you're mapping some category theory FP onto the problem, but it's a more general solution to lift implicit conversations into containers as needed. Notice how they chain by using one implicit conversation method that <em>takes</em> a more limited implicit argument.</p> <p>ALSO, this should make the examples work:</p> <pre><code>scala&gt; val tmp = Option(Foo(1)) tmp: Option[Foo] = Some(Foo(1)) scala&gt; val y: Option[Bar] = tmp y: Option[Bar] = Some(Bar(1)) </code></pre> <p>And make your usage of <code>Some</code> more dangerous:</p> <pre><code>scala&gt; val tmp = Some(Foo(1)) tmp: Some[Foo] = Some(Foo(1)) scala&gt; val y: Option[Bar] = tmp &lt;console&gt;:25: error: could not find implicit value for parameter functor: fun.Functor[Some] val y: Option[Bar] = tmp ^ </code></pre> <p>That's telling you that <em>variance</em> is critical, and interacts with implicits. My guess is you ran into a very rare, probably hard to fix bug that can be avoided using other techniques. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload