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

Scalac outputs least informative error #10234

Open
scabug opened this issue Mar 17, 2017 · 6 comments
Open

Scalac outputs least informative error #10234

scabug opened this issue Mar 17, 2017 · 6 comments

Comments

@scabug
Copy link

scabug commented Mar 17, 2017

class Foo[T <: String]
class Bar[T]
def foo[T](implicit bar: Bar[T]) = bar
implicit def mkFooBar[A, T[x] <: Foo[x]]: Bar[T[A]] = new Bar[T[A]]

foo[Foo[String]]

If you compile this code in one go, you get the following error:

error: could not find implicit value for parameter bar: Bar[Foo[String]]
       foo[Foo[String]]
          ^

This error is actually caused by another error:

error: type arguments [x] do not conform to class Foo's type parameter bounds [T <: String]
       implicit def mkFooBar[A, T[x] <: Foo[x]]: Bar[T[A]] = new Bar[T[A]]
                                        ^

This is the error you actually have to fix to get the code working, but the compiler doesn't show it and leaves you guessing what the problem is.

@scabug
Copy link
Author

scabug commented Mar 17, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10234?orig=1
Reporter: Jasper-M
Affected Versions: 2.12.1

@scabug scabug added the quickfix label Apr 7, 2017
@atiqsayyed
Copy link

Can I pick this Issue?? If somebody can provide the details it'd be great help

@SethTisue
Copy link
Member

@atiqsayyed I'd suggest starting by finding the place in the code where the error is coming from.

I'm not certain this is actually a "quick" fix — implicit search is pretty hairy stuff. if you get into it and find it's too hard, it would still be valuable even just to record your investigation here as a starting point for the next person.

@som-snytt
Copy link

I don't know why scalacenter doesn't run a contest for least informative error.

$ scala -Vimplicits -language:_
Welcome to Scala 2.13.0 (OpenJDK 64-Bit Server VM, Java 11.0.3).
Type in expressions for evaluation. Or try :help.

scala> :pa
// Entering paste mode (ctrl-D to finish)

class Foo[T <: String]
class Bar[T]
def foo[T](implicit bar: Bar[T]) = bar
implicit def mkFooBar[A, T[x] <: Foo[x]]: Bar[T[A]] = new Bar[T[A]]


// Exiting paste mode, now interpreting.

       implicit def mkFooBar[A, T[x] <: Foo[x]]: Bar[T[A]] = new Bar[T[A]]
                                        ^
On line 4: error: type arguments [x] do not conform to class Foo's type parameter bounds [T <: String]

scala> :pa
// Entering paste mode (ctrl-D to finish)

class Foo[T <: String]
class Bar[T]
def foo[T](implicit bar: Bar[T]) = bar
implicit def mkFooBar[A, T[x] <: Foo[x]]: Bar[T[A]] = new Bar[T[A]]

foo[Foo[String]]

// Exiting paste mode, now interpreting.


foo[Foo[String]]
   ^
<pastie>:6: mkFooBar is not a valid implicit value for Bar[Foo[String]] because:
typing TypeApply reported errors for the implicit tree: kinds of the type arguments (String,Foo) do not conform to the expected kinds of the type parameters (type A,type T).
Foo's type parameters do not match type T's expected parameters:
type T's bounds <: String are stricter than type x's declared bounds >: Nothing <: Any

foo[Foo[String]]
   ^
<pastie>:6: this.mkFooBar is not a valid implicit value for Bar[Foo[String]] because:
typing TypeApply reported errors for the implicit tree: kinds of the type arguments (String,Foo) do not conform to the expected kinds of the type parameters (type A,type T).
Foo's type parameters do not match type T's expected parameters:
type T's bounds <: String are stricter than type x's declared bounds >: Nothing <: Any

foo[Foo[String]]
   ^
<pastie>:6: error: could not find implicit value for parameter bar: Bar[Foo[String]]

@SethTisue SethTisue added this to the Backlog milestone Jul 29, 2019
@som-snytt
Copy link

som-snytt commented Dec 23, 2022

-- Error: t10234.scala:9:29 --------------------------------------------------------------------------------------------
9 |  def test = foo[Foo[String]]
  |                             ^
  |                  No given instance of type Bar[Foo[String]] was found for parameter bar of method foo in class C.
  |                  I found:
  |
  |                      this.mkFooBar[A, T]
  |
  |                  But method mkFooBar in class C does not match type Bar[Foo[String]].
1 error found

The ticket title reads like an Onion headline!

@Jasper-M
Copy link
Member

You won't BELIEVE these 27 errors that the scala compiler is hiding from you!

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

6 participants