Skip to content

Implicit conversions to refinements of Any/AnyVal/AnyRef should be allowed #9403

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

Closed
sjrd opened this issue Jul 21, 2020 · 0 comments · Fixed by #10975
Closed

Implicit conversions to refinements of Any/AnyVal/AnyRef should be allowed #9403

sjrd opened this issue Jul 21, 2020 · 0 comments · Fixed by #10975
Milestone

Comments

@sjrd
Copy link
Member

sjrd commented Jul 21, 2020

Minimized code

import scala.reflect.Selectable.reflectiveSelectable

object Test {
  def main(args: Array[String]): Unit = {
    def fCompareToBoolean(x: { def compareTo(y: java.lang.Boolean): Int }, y: Boolean): Int =
      x.compareTo(y)
    assert(fCompareToBoolean(false, true) < 0)
  }
}

Output

-- Error: tests/run/hello.scala:7:29 -------------------------------------------
7 |    assert(fCompareToBoolean(false, true) < 0)
  |                             ^^^^^
  |the result of an implicit conversion must be more specific than Object{compareTo(y: Boolean): Int}
1 error found

Expectation

The code compiles and runs successfully, as it does on Scala 2.

Notes

Implicit conversions to Any/AnyVal/AnyRef were disallowed in #8453 to fix the issue #6336. Apparently the introduced check was too strict, as it also disallows implicit conversions to refinements, which Scala 2 doesn't do.

This was discovered while trying to enable the Scala.js test ReflectiveCallsTest.scala, but the issue arises on the JVM as well.

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

Successfully merging a pull request may close this issue.

2 participants