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

Implicit conversions with by-name parameters should have lower precedence #5346

Closed
Duhemm opened this issue Oct 31, 2018 · 1 comment
Closed

Comments

@Duhemm
Copy link
Contributor

Duhemm commented Oct 31, 2018

The Scala language specification states in section 7.3 Views that:

[...] call-by-value implicits take precedence over call-by-name implicits.

The following snippet exercises exactly this; conv1 should be selected over conv2. This is the behaviour of scalac. Dotc complains about ambiguous conversions:

import scala.language.implicitConversions

object O {

  class A(x: Int)

  implicit def conv1(x: Int): A = new A(x)
  implicit def conv2(x: => Int): A = new A(x)

  def buzz(y: A) = ???

  def main(args: Array[String]): Unit = {
    buzz(1)
  }
}

Compiles fine with scalac 2.13.0-M5
dotc (same result with or without -language:Scala2):

sbt:dotty> dotc Bar.scala -explain -language:Scala2
-- [E007] Type Mismatch Error: Bar.scala:13:9 ----------------------------------
13 |    buzz(1)
   |         ^
   |found:    Int(1)
   |required: O.A
   |
   |
   |Note that implicit conversions cannot be applied because they are ambiguous;
   |both method conv1 in object O and method conv2 in object O convert from Int(1) to O.A
one error found

Is this difference between Scala 2 and 3 intentional?

@allanrenucci
Copy link
Contributor

Is this difference between Scala 2 and 3 intentional?

I am pretty sure it is: dotty-staging/scalacheck@00f01af

odersky added a commit that referenced this issue Dec 17, 2018
Fix #5346: Refine implicit resolution spec
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Jan 5, 2019
Add discussion of by-name parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants