-
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
Resolve name when named imp is behind wild imps #21871
Conversation
When a named import (such as `import bug.util.List`) is defined before two clashing wildcard imports (`import bug.util.*; import java.util.*`) the name "List" should resolve to it, rather than a resolution error being emitted. This was due to the fact that `findRefRecur` didn't return the precedence at which it found that import, `checkImportAlternatives` used the `prevPrec` to `checkNewOrShadowed`. Now we check against the entire `foundResult`, allowing an early named import to be picked over later wildcard imports.
I was dubious at first because the motivation is "how Java imports work". My previous questions about name resolution in Dotty came down to understanding contexts not scopes. However, the spec only talks about scopes. Scala 2 has the same current behavior. As a lover of wildcards, why doesn't that come up more often? I must further spool up So with a grain of salt, this modified example from the spec, with an ambiguating import, and a second import to disambiguate, is still ambiguous:
where
yielding
That is unchanged from 3.5.2 (actually), but Scala 2 complains about the competing wildcards:
This variant of the test works as expected, and 3.5.2 complains about the wildcards:
|
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.
Can we piush this to staging please? That makes it easier for me to run my own diff tool.
It's going to be difficult to review, since there are a lot of changes in code that I know to be very subtle.
When a named import (such as `import bug.util.List`) is defined before two clashing wildcard imports (`import bug.util.*; import java.util.*`) the name "List" should resolve to it, rather than a resolution error being emitted. This was due to the fact that `findRefRecur` didn't return the precedence at which it found that import, `checkImportAlternatives` used the `prevPrec` to `checkNewOrShadowed`. Now we check against the entire `foundResult`, allowing an early named import to be picked over later wildcard imports. Fixes #18529 (Replaces #21871)
When a named import (such as
import bug.util.List
) is defined beforetwo clashing wildcard imports (
import bug.util.*; import java.util.*
)the name "List" should resolve to it, rather than a resolution error
being emitted.
This was due to the fact that
findRefRecur
didn't return theprecedence at which it found that import,
checkImportAlternatives
usedthe
prevPrec
tocheckNewOrShadowed
. Now we check against the entirefoundResult
, allowing an early named import to be picked over laterwildcard imports.
Fixes #18529