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

compiler sometimes(?) allows ambigous implicit imports, sometimes it refuses to compile #5376

Closed
scabug opened this issue Jan 14, 2012 · 4 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 14, 2012

i was experimenting with implicits trying to figure out exactly which implicit is picked when, and there was a problem which i cannot explain other than "it's not a feature, it's a bug!"

Correct1:
i import 2 conversions which are ambigous, compiler complains, everything ok.

Bug1:
Same situation, both conversions are imported - but the compiler doesn't complain.

see the whole thread for more details:
http://devnet.jetbrains.net/thread/433043

@scabug
Copy link
Author

scabug commented Jan 14, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5376?orig=1
Reporter: Dennis Haupt (hamsterofdeath)
Affected Versions: 2.9.1
See #4831
Attachments:

  • Bug1.scala (created on Jan 14, 2012 2:48:28 PM UTC, 839 bytes)
  • Correct1.scala (created on Jan 14, 2012 2:48:28 PM UTC, 1181 bytes)

@scabug
Copy link
Author

scabug commented Jan 15, 2012

@paulp said:
It would be helpful if you would not include large amounts of extraneous detail, and when attempting to contrast behavior of two pieces of code, if they did not appear to be written for two different bug reports. What are you are trying to report is presumably captured in the following.

object Test {
  object O1 { implicit def f(s: String): Int = 1 }
  object O2 { implicit def f(s: String): Int = 2 }
  object O3 { implicit def f1(s: String): Int = 3 }
  object O4 { implicit def f2(s: String): Int = 4 }
  
  // Import two implicits with the same name in the same scope.
  def m1 = {
    import O1._
    import O2._

    // Implicit usage compiles.
    "a": Int
    // Explicit call to f fails.
    f("a")
    // ./c.scala:9: error: reference to f is ambiguous;
    // it is imported twice in the same scope by
    // import O2._
    // and import O1._
    //     f("a")
    //     ^
  }

  // Import two with different names in the same scope.
  def m2 = {
    import O3._
    import O4._
  
    // Explicit calls compile.
    f1("a")
    f2("a")

    // Implicit usage fails.
    "a": Int
    // ./a.scala:36: error: type mismatch;
    //  found   : String("a")
    //  required: Int
    // Note that implicit conversions are not applicable because they are ambiguous:
    //  both method f1 in object O3 of type (s: String)Int
    //  and method f2 in object O4 of type (s: String)Int
    //  are possible conversion functions from String("a") to Int
    //     "a": Int
    //     ^
  }
}

@scabug
Copy link
Author

scabug commented Jun 4, 2012

@retronym said:
I'm working on a fix for #4270, which will also fix this, as they are closely kindred tickets.

https://github.com/retronym/scala/compare/ticket/4270

@scabug
Copy link
Author

scabug commented Jun 19, 2012

@retronym said:
Merged in scala/scala@736f622f7

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

No branches or pull requests

2 participants