Skip to content

Bogus Compile error on implicit ambiguity #9861

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 Jul 14, 2016 · 8 comments
Closed

Bogus Compile error on implicit ambiguity #9861

scabug opened this issue Jul 14, 2016 · 8 comments

Comments

@scabug
Copy link

scabug commented Jul 14, 2016

Code located here: https://github.com/axos88/scala-bug-implicit-ambiguity
Unfortunately I did not find an easy way to reduce it further, or remove the dependency on spray-json.

Compiler currently errs with:

$ sbt ';clean;compile'
[info] Set current project to implicit-bug (in build file:///)
[success] Total time: 0 s, completed Jul 14, 2016 4:42:01 PM
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 2 Scala sources to <pwd>/target/scala-2.11/classes...
[error] <pwd>/src/main/scala/example/json/JsonProtocol.scala:30: could not find implicit value for evidence parameter of type spray.json.DefaultJsonProtocol.JF[example.Foo]
[error]     implicit val bazFormat = jsonFormat2(Baz)
[error]                                         ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 3 s, completed Jul 14, 2016 4:42:04 PM

Take a look at the file: https://github.com/axos88/scala-bug-implicit-ambiguity/blob/master/src/main/scala/example/json/JsonProtocol.scala

The following things fix the error:

  1. CHANGING THE ORDER of line 30 and 31 (! wtf?)
  2. Removing the T: TypeTag restriction from line 11 (resulting in def stringFormat[T])
  3. Removing line 22, or the implicit from Foo's companion class (makes sense).

The fact that #1 fixes it suggests it is a compiler bug, or an undetected undefined behaviour.

Expected Behaviour:

Compilation should succeed, and fooFormatHighPrio should take precedence over fooFormatLowPrio and FooFormatLowestPrio when one has JsonProtocol._ in scope.

OR

Error with ambigous implicits for JsonFormat[Foo]

Current Behaviour:

Misterious error message about NOT finding an implicit, whereas there are multiple candidates with different priorities.

@scabug
Copy link
Author

scabug commented Jul 14, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9861?orig=1
Reporter: Akos Vandra (axos88)
Affected Versions: 2.11.8
See #8697

@scabug
Copy link
Author

scabug commented Jul 14, 2016

@som-snytt said:
I haven't tried, but I see your implicits don't have explicit types. Relying on inferred types creates textual ordering dependencies, so it's not a good idea and eventually may be disallowed.

@scabug
Copy link
Author

scabug commented Jul 15, 2016

Akos Vandra (axos88) said:
Hello.

Explicitly stating the type of the quxFormat fixes the compilation error. Now this is AGAIN something that seems unrelated to the line for which the implicitnot found error is thrown.

I hope you agree that this is not expected behaviour, and that the raise error does not help at all identifying the issue.
Can you please explain what is happening here?

@scabug
Copy link
Author

scabug commented Jul 15, 2016

Akos Vandra (axos88) said:
The compiler should be abel to imply the type of the implicits easily.

@scabug
Copy link
Author

scabug commented Jul 16, 2016

Akos Vandra (axos88) said:
This is not the duplicate of #8697.

The implicits whose order is changed in the file are NOT related, and have nothing in common with the implicit that is NOT being found.
Basically adding a new line with an implicit value AFTER the questioned file creates an error in the line before.

@scabug
Copy link
Author

scabug commented Jul 16, 2016

@som-snytt said (edited on Jul 16, 2016 7:48:21 PM UTC):
Moving stringFormat to object package lets it compile without other changes. In fact, importing only JsonProtocol.stringFormat suffices.

Sorry for the edit noise. Just following typer-debug output.

@scabug
Copy link
Author

scabug commented Aug 3, 2016

@SethTisue said:
I'm afraid it's unlikely this will get further attention unless you can isolate and minimize it further. I'm provisionally closing the ticket; we can reopen if you can successfully isolate it.

@scabug scabug closed this as completed Aug 3, 2016
@scabug
Copy link
Author

scabug commented Aug 3, 2016

@som-snytt said:
This is the one where the call to stringFormat in object Foo induces implicit search (augmentString and a TypeTag), which causes the imported symbols to be checked. Conversely to my previous comment,

import JsonProtocol.{ stringFormat, barFormat, bazFormat } 

suffices to break it. barFormat uses stringFormat, baz uses formatter for Foo, Bar.

@scabug scabug added the needinfo label Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant