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

New ambiguous implicits error in Scala 2.11.4 (works in 2.11.2) with macros #8947

Closed
scabug opened this issue Oct 29, 2014 · 6 comments
Closed

Comments

@scabug
Copy link

scabug commented Oct 29, 2014

If you compile a.scala, then b.scala with 2.11.4, then you get the ambiguous implicits error shown beneath. For the problem to be apparent, a.scala must be compiled with 2.11.4, but b.scala can be compiled with either 2.11.2 or 2.11.4 (i.e. I'd infer that the problem is with the binaries produced by 2.11.4).

The most interesting thing about it is that the method foo and the macro seem to be completely unrelated. The error still occurs if foo gets moved to a separate object.

You can also see the problem in the REPL.

a.scala:

import language.experimental.macros
import scala.reflect.macros._
object X {
  def foo[D] = new Array[Any](0).map(_.asInstanceOf[D])
  def extractor: Any = macro extractorMacro
  def extractorMacro(c: blackbox.Context): c.Expr[Any] =
    c.universe.reify(new { def something(data: Any) = ??? })
}

b.scala:

object Test { X.extractor }

output:

> scalac a.scala && scalac b.scala
b.scala:1: error: ambiguous implicit values:
 both value StringCanBuildFrom in object Predef of type => scala.collection.generic.CanBuildFrom[String,Char,String]
 and method $conforms in object Predef of type [A]=> <:<[A,A]
 match expected type T
object Test { X.extractor }
                ^
one error found
@scabug
Copy link
Author

scabug commented Oct 29, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8947?orig=1
Reporter: @propensive
Affected Versions: 2.11.4

@scabug
Copy link
Author

scabug commented Oct 29, 2014

@paulp said:
Roll those non-determinism dice and say "baby needs a new pair of shoes."

Here's a way to get the same error with one little file, on 2.11.2 or 2.11.4, which may serve to illustrate what's going on. Then again, it may not.

object X { implicitly }

@scabug
Copy link
Author

scabug commented Oct 29, 2014

@retronym said:
My bet is that the non determinism once again comes from the MRU-cache like sorting performed in implicit search. I'll take a look.

@scabug
Copy link
Author

scabug commented Oct 30, 2014

@retronym said:
Interesting, we now typecheck a naked call to implicitly

https://gist.github.com/retronym/60b1abfecb69970bf543

@scabug
Copy link
Author

scabug commented Oct 30, 2014

@retronym said (edited on Oct 30, 2014 2:11:17 AM UTC):
We've got a new form of cross talk: tree attachments on EmptyTree!

scala/scala#4083

@propensive I've listed a few workarounds in the test case in the pull request.

@scabug scabug closed this as completed Nov 7, 2014
@scabug
Copy link
Author

scabug commented Nov 7, 2014

@propensive said:
Thanks for the quick turnaround, Jason!

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