Closed
Description
Minimized code
trait Magic[F]:
extension (x: Int) def read: F
object Magic:
given Magic[String]:
extension(x: Int) def read: String =
println("In string")
s"$x"
opaque type Foo = String
object Foo:
import Magic.{given _}
def apply(s: String): Foo = s
given Magic[Foo]:
extension (x: Int) def read: Foo =
println("In foo")
Foo(s"$x")
def test: Unit =
(3.read: Foo)
@main def test = {
Foo.test
}
Output
In string
Expectation
In foo
Remarks
- If
import Magic.{given _}
is removed, the output is as expected. The question is: should this import change the behavior?given Magic[Foo]
should be more specific and preferred togiven Magic[String]
Snippet
https://scastie.scala-lang.org/vincenzobaz/tGQhSpQ8TQyiOeTNAvSGbA/104