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
Misleading error when "implicitly" cannot find value when used without type arg #9427
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9427?orig=1 |
@som-snytt said: package impillicitly
import scala.Predef.{
$conforms => _,
StringCanBuildFrom => _,
fallbackStringCanBuildFrom => _,
_
}
object Test extends App {
class Imp
//implicit val imp: Imp = new Imp
println(implicitly : Imp)
} and
|
it's not clear here what a solution plan would even look like. adding special-case code for Dotty is similar:
|
The issue is about using scala> val i: Int = implicitly
1 |val i: Int = implicitly
| ^
|no implicit argument of type T was found for parameter ev of method implicitly in object DottyPredef |
I stumbled upon this today. Isn't there a way we can improve the error message here? It seems baffling to me that the compiler doesn't infer that |
If you have
then for some reason scalac is not convinced it should fix |
Fix the sources because of this bug scala/bug#9427. The test was for some reason passing locally, thanks to these changes it's not anymore. Fixing this and the other packageobjects tests is left as future work.
It's normal. The compiler will prefer solutions that give a more precise result type, this is usually what you want. |
λ. scala
________ ___ / / ___
/ __/ __// _ | / / / _ |
__\ \/ /__/ __ |/ /__/ __ |
/____/\___/_/ |_/____/_/ | |
|/ version 2.13.1
scala> implicitly
res0: Nothing => Nothing = generalized constraint |
@som-snytt why the adaptation warning? |
There's a warning in the REPL but not in the test 🤔 |
I see the linked PR produces the desired message. I wonder why it doesn't do more for #6127 I couldn't reproduce the adaptation warning, but in the debug output it looks for conversions of Unit, so I think it still tries
|
I have noticed that the
implicitly
method gives a rather strange error message if it is used without arguments and the implicit value cannot be found:If you pass it an explicit type param, it gives a much more sensible error:
This looks to me like a minor compiler bug.
I like using "implicitly" without type args when the type can be inferred, e.g.
rather than, say:
... but this does give very misleading errors if one of the implicits can't be found, as shown above.
Minimised Repro case
Expected result:
Observed result:
Related issues:
#5801 looks similar, but that's marked as fixed in 2.10
#8947 looks related, but marked fixed in 2.11.5
The text was updated successfully, but these errors were encountered: