Skip to content

Overloaded functions from package objects trigger unnecessary implicit conversions. #4598

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
scabug opened this issue May 17, 2011 · 2 comments

Comments

@scabug
Copy link

scabug commented May 17, 2011

In the following code an implicit conversion gets applied even though it is not required. The code works correctly when a full function name (including package) is used.

object Main {

  def main(args: Array[String]) {
    import pkg._

    val p0 = new PrivateI(new Clue)
    println("I was given a clue, and found a " + p0.found + ".")

    val p1 = new Policeman(new Clue)
    println("I was given a clue, and found a " + p1.found + ".")
  }
}

package pkg {

  class Clue
  trait Red
  trait Herring[T]
  class RedHerring extends Herring[Red]

  class PrivateI(val clue: Clue) {
    def found = find(clue)
  }

  class Policeman(val clue: Clue) {
    def found = pkg.find(clue)
  }
}

package object pkg {
  implicit def convert(s: Clue) :RedHerring = new RedHerring

  def find(clue: Clue) :String = clue.getClass.getSimpleName
  def find(fish: Herring[_]) :String = fish.getClass.getSimpleName
}

=== What is the expected behavior? ===
"find(Clue)" should be called both times.

=== What do you see instead? ===
An implicit conversion gets applied and "find(Herring[_])" is called instead.

=== What versions of the following are you using? ===

  • Scala: 2.9.0.final
  • Java: 1.6.0_24
  • Operating system: Arch64
@scabug
Copy link
Author

scabug commented May 17, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4598?orig=1
Reporter: @lexn82

@scabug
Copy link
Author

scabug commented May 17, 2011

@harrah said:
#1987

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

1 participant