Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Hint about forbidden combination of implicit values and conversions #16735
Hint about forbidden combination of implicit values and conversions #16735
Changes from 15 commits
ea13cad
fc9acd7
393dab4
1d7f8dc
208071a
3f42e53
6bded27
76c826d
adc1995
82d69a7
859d30b
b5755de
9579aa5
ebb616c
98bf4b2
dda91bb
2584cf6
95c9dfb
809f9fc
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, what was the problem with using
ctx.implicits.eligible(ViewProto(...))
to find out if an implicit value can be converted to the type that we're searching for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that in case the implicit value was something like
given [T <: Bar]: Foo[T]
, it would've neededwildApprox
to fill in the type argument toFoo
andFoo[?]
would've been too permissive, but after your comment, I just realizedwildApprox
takes bounds into account. It'd be clearer than the current approach and would give us the conversions that would apply to the implicits. I'll try that later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I tried the following to check if there are applicable conversions:
ctx.implicits.eligible( ViewProto( wildApprox(imp.underlying.widen.finalResultType), fail.expectedType ) ).nonEmpty
This works fine when the conversion doesn't have any type parameters (
summon[String]
andimplicitly[String]
work fine in the test), but when it does have type parameters, all the implicits in scope are listed (summon[Option[Int]]
andimplicitly[Option[Int]]
don't work). Gonna have to do some more investigating there. I made another branch to test this out. Here's the first run.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to dig into that and it seems that we were trying to reinvent the wheel. There's already the method
viewExists
available in this context, which seems to does whatcanBeConverted
was supposed to do, and it even has the same signatureThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find!