Skip to content

Fix #1747: Improve error message for Scala/Java type mismatch #1984

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

Merged
merged 6 commits into from
Feb 21, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 15, 2017

No description provided.

Omit the `=>' if a PolyType has a MethodType as result type.
We used to "fill-in" with zeroes if variances were missing. I now
think that;'s too error-prone. Better define all variances explicitly.
val found1 = dropJavaMethod(found)
val expected1 = dropJavaMethod(expected)
if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1))
"\n (Note that Scala's and Java's representation of this type differs)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not be enough for the user to understand the issue. In the example we would get

overriding method toArray in trait Collection of type [T](x$0: Array[T])Array[T];
       method toArray of type [T](a: Array[T])Array[T] has incompatible type
       (Note that Scala's and Java's representation of this type differs)

Would it be possible to hint that to make the representation match one would need to write
def toArray[T](a: Array[T with Object]): Array[T with Object]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but it is really tricky and would require quite a bit of code. In short interoperating with Java using arrays requires a lot of context knowledge. Hard to condense that in an error message.

@nicolasstucki
Copy link
Contributor

That is all. Otherwise LGTM.

@odersky odersky merged commit 6189ffe into scala:master Feb 21, 2017
@allanrenucci allanrenucci deleted the fix-#1747-v2 branch December 14, 2017 16:59
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

Successfully merging this pull request may close these issues.

2 participants