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

Confusing error message #5839

Closed
scabug opened this issue May 27, 2012 · 5 comments
Closed

Confusing error message #5839

scabug opened this issue May 27, 2012 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 27, 2012

object Test {
  def goo[T](x: Int => T): T = x(1)
  implicit def f(x: Int): String = ""
  def foo(x: Int): Int = x + 1
  val x: String = goo(foo _)
  def foo(x: String => String) = 1
}

Error message is quite confusing:
error: type mismatch;
found :
required: Int => String
val x: String = goo(foo _)

First of all, in this example it's quite simple to choose right 'foo' function.
However even overload resolution fails, error should be about overload resolution, not about "" type.

@scabug
Copy link
Author

scabug commented May 27, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5839?orig=1
Reporter: @Alefas
Affected Versions: 2.10.0-M3
Duplicates #5735

@scabug
Copy link
Author

scabug commented May 27, 2012

@som-snytt said:
It groks val x = goo(foo).

@scabug
Copy link
Author

scabug commented May 27, 2012

@som-snytt said:
I guess that in the presence of an expected type pt, implicit search is failing and overload resolution doesn't get a chance.

The language in 7.3 is that if a view is found, is converted to v(e).

That implies: if no view is found, la-di-da.

For overload resolution, this is a value context and it should select the foo that is compatible with Int => String, where compatible means conforming after applying implicits.

But is the result different? The intuition here is that it should apply f to the result of foo, but I think this is still required:

implicit def f2(v: Int => Int): Int => String = { (x: Int) => f(x) }

If this were an application of foo(1) where a String is expected, it would supply the implicit f.

(In my previous comment, it infers Int. Disclaimer: my attention is divided by child care, and I'm just learning how all this works.)

@scabug
Copy link
Author

scabug commented May 27, 2012

@hubertp said:
Yes, that's correct. The implicit is not applied at all because typically in a non-overloaded scenario it would be applied during eta-expansion. In this case we don't even get to eta-expansion since we have to deal with overloading first and at that point the provided implicit is useless.
There is still a problem with the error message which I need to fix.

@scabug
Copy link
Author

scabug commented Jun 27, 2012

@hubertp said:
Closed by #782

@scabug scabug closed this as completed Jun 27, 2012
@scabug scabug added this to the 2.10.0-M4 milestone Apr 7, 2017
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