Skip to content

Turn mismatch given errors into given not found errors #8611

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

Conversation

julienrf
Copy link
Contributor

Fixes #8053

When a given candidate turns out to not be applicable we used to report that
there is a mismatch between the candidate type and the expected type.

However, I believe that if there is a type mismatch, then the candidate should
not be a candidate in the first place.

I’ve changed the failure to be a NoMatchingImplicitsFailure instead of a mismatch.

Hopefully this won’t have a negative impact. I’ve added a couple of tests that used to
report a mismatch for the "candidate" $conforms[Nothing] and they now report that
no given could be found. One existing test was broken by my changes. This test was
very similar to the ones described in #8053, so I’ve changed the test expectation.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@julienrf
Copy link
Contributor Author

How can I reproduce the test failure? I’ve run dotty-compiler-bootstrapped/test but didn’t get the failure reported by the CI.

@smarter
Copy link
Member

smarter commented Mar 26, 2020

My guess is that there's some non-determinism in the order in which we look for implicits, which leads to non-deterministic error output.

@odersky
Copy link
Contributor

odersky commented Mar 26, 2020

I doubt this is an improvement. At least the previous strategy was intentional. The idea is to always provide the most specific information. If there is just one candidate that could plausibly match, and it doesn't in the end, I want to find out why by getting a type mismatch error. "Implicit not found" is much less helpful.

@julienrf
Copy link
Contributor Author

@odersky I don’t completely agree: it’s true that it’s better to provide the most precise information as possible to the user, but in our case I think the information we provide is useless: if the candidate can’t be typed, then it should not be a candidate in the first place. But maybe there are other kinds of mismatch that could be worth reporting?

Do we agree at least that inferring $conforms[Nothing] or refl[Nothing] is useless because these types are uninhabited anyway? Could we at least add a special case to turn those two specific “mismatches” into “not found”?

@odersky
Copy link
Contributor

odersky commented Mar 28, 2020

Do we agree at least that inferring $conforms[Nothing] or refl[Nothing] is useless because these types are uninhabited anyway? Could we at least add a special case to turn those two specific “mismatches” into “not found”?

Yes, that makes sense!

@julienrf julienrf force-pushed the replace-implicit-mismatch-with-implicit-not-found branch from da29c0a to d072148 Compare March 30, 2020 07:31
if (adapted.show == "$conforms[Nothing]" || adapted.show == "<:<.refl[Nothing]")
NoMatchingImplicitsFailure
else
SearchFailure(adapted.withType(new MismatchedImplicit(ref, pt, argument)))
Copy link
Contributor Author

@julienrf julienrf Mar 30, 2020

Choose a reason for hiding this comment

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

Note that there are (and there were) no tests to exercise this code path.

@julienrf julienrf force-pushed the replace-implicit-mismatch-with-implicit-not-found branch 2 times, most recently from 307d51b to 43876a4 Compare March 30, 2020 14:31
@julienrf julienrf force-pushed the replace-implicit-mismatch-with-implicit-not-found branch 2 times, most recently from 2aface6 to 63605ca Compare March 30, 2020 19:30
@julienrf julienrf assigned smarter and unassigned julienrf Mar 30, 2020
| ..
| I found:
|
| scala.math.Ordering.ordered[A](/* missing */implicitly[scala.math.Ordering.AsComparable[B]])
Copy link
Member

Choose a reason for hiding this comment

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

Could you use some locally defined implicits instead of depending on what is in the standard library? It makes the test more stable in case the library changes, and it seems that even when the library don't change our output is not stable based on earlier failures of this PR (this is something we should try to fix, but it might be hard).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I can do that. On the other hand, please be aware that by creating artificial test scenarios we might simplify the reality and miss bugs/limitations.

This is what motivated this PR: the existing test suite for import suggestions was only based on artificial scenarios and we didn’t know that the output of the compiler was not good on some real world cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and squashed.

@smarter smarter assigned julienrf and unassigned smarter Apr 5, 2020
…[Nothing]` and `<:<.refl[Nothing]`

Fixes scala#8053

When a given candidate turns out to not be applicable we used to report that
there is a mismatch between the candidate type and the expected type.

The goal is to report an error as precise as possible to the user. However, in some cases
showing the inferred candidate brings no value to the user, especially when the candidate
is uninhabited.

I’ve changed the failure to be a `NoMatchingImplicitsFailure` instead of a mismatch when
`$conforms[Nothing]` or `<:<.refl` are inferred because these values are uninhabited and
might be confusing for end users.
@julienrf julienrf force-pushed the replace-implicit-mismatch-with-implicit-not-found branch from 63605ca to d525c59 Compare April 6, 2020 07:21
@julienrf julienrf assigned smarter and unassigned julienrf Apr 6, 2020
@smarter smarter merged commit 588ac1b into scala:master Apr 6, 2020
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.

$conforms[Nothing] shows up as a placeholder for missing implicits
4 participants