Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop distinction between implicit conversions with call-by-value and call-by-name parameters #598

Open
adriaanm opened this issue Jan 14, 2019 · 1 comment
Labels
dotty towards scala 3

Comments

@adriaanm
Copy link
Contributor

for dotty compat, see scala/scala3#5633

@adriaanm adriaanm added the dotty towards scala 3 label Jan 14, 2019
@adriaanm adriaanm added this to the 2.14 milestone Jan 14, 2019
@som-snytt
Copy link

I haven't spent much time with dotty yet, but the dotty spec change is misleading in terms of Scala 2. Static overloading already prefers f(X) to f(=>X) when the relative weight is the same, so the dotty spec example should just continue to compile.

Here, conversion prefers by-value because of the two-pass rule, but overloading prefers by-name because it is more specific.

case class C(i: Int)
object C extends Imps {
  implicit def f(b: => B): C = C(42)
}

class Imps {
  implicit def f(a: A): C = C(17)
}

class A
class B extends A

object Main {
  def main(args: Array[String]) = println {
    (null.asInstanceOf[A] : C, C.f(null.asInstanceOf[B])). // (C(17),C(42))
  }
}

The same experiment with both in C differing only in by-name

  implicit def g(a: => A): C = C(42)
  implicit def g(a: A): C = C(17)

yields (C(17),C(17)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotty towards scala 3
Projects
None yet
Development

No branches or pull requests

2 participants