-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix how implicit candidates are combined #18321
Conversation
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 think this is getting a bit too complex for comfort.
One alternative approach to consider is to have a smarter merge where we don't immediately designate a shadowed set, but merge outerImplicits and innerImplicits according to what is better:
- high levels beat lower
- at equal level, definitions beat imports and named imports beat wildcard imports
Something like this: private def combineEligibles(ownEligible: List[Candidate], outer: ContextualImplicits): List[Candidate] =
val outerEligible = outer.uncachedEligible(tp)
if ownEligible.isEmpty then outerEligible
else if outerEligible.isEmpty then ownEligible
else
val ownNames = mutable.Set(ownEligible.map(_.ref.implicitName)*)
if level == outer.level then
val keptOuters = outerEligible.filterConserve: cand =>
if ownNames.contains(cand.ref.implicitName) then
val keepOuter = cand.level == level && cand.bindingPrec.id > bindingPrec.id
if keepOuter then ownNames -= cand.ref.implicitName
keepOuter
else false
val keptOwn = ownEligible.filterConserve: cand =>
ownNames.contains(cand.ref.implicitName)
keptOwn ::: keptOuters
else
ownEligible ::: outerEligible.filterConserve: cand =>
!ownNames.contains(cand.ref.implicitName) I assume a field Not sure what to do under 3.0-migration. |
d045a8b
to
aeb6a9f
Compare
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.
LGTM now
No description provided.