-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-2458 Import shadows def in other unit #5339
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
|
This doesn't fix SI-9552. The import should be higher precedence than definition in other file. Maybe the package object fools a depth check? and separate unit |
|
Fixes the Java check for explicit import. Scala lets wildcard import hide foreign definition. |
|
Suffers from the broken build. |
|
Some documentation notes the bug and should be updated: |
|
@som-snytt what happened to this PR? Are the bugtracker entries up-to-date currently? (https://issues.scala-lang.org/browse/SI-2458 is closed, https://issues.scala-lang.org/browse/SI-9552 is open, and I'm confused). |
|
@Blaisorblade The old issue was closed prematurely when the spec was clarified; this PR was meant to be implementation which also nails down the newer issue (which also objects to the behavior as specified). I don't remember the build status, so I'll have to revisit it. |
|
@som-snytt Thanks — it sounds like all the open parts are tracked by the newer issue. I dread unfixed closed issues and forgotten bugs. |
83fb60c to
cdad662
Compare
6c49757 to
db259cd
Compare
|
Previous failure was due to cycle in There was also an import in scaladoc that was not to spec. |
|
This idiom now inoculates against accidental local dir named Too bad that's not more useful. |
5553582 to
81f1366
Compare
build.sbt
Outdated
| // Avoid circular dependencies for scalaInstance (see https://github.com/sbt/sbt/issues/1872) | ||
| managedScalaInstance := false, | ||
| //maxErrors := 500, | ||
| maxErrors := 5, |
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.
Meant to set that to zero.
411dd5f to
930594a
Compare
|
|
||
| val tpe = typer.packedType(tree, NoSymbol) | ||
| val ReifiedType(_, _, tpeSymtab, _, rtpe, tpeReificationIsConcrete) = `package`.reifyType(global)(typer, universe, mirror, tpe, concrete = false) | ||
| val ReifiedType(_, _, tpeSymtab, _, rtpe, tpeReificationIsConcrete) = reifyTypeGlobal(global)(typer, universe, mirror, tpe, concrete = false) |
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.
This was good, when you got packages and methods named reify.
| /** | ||
| * This class implements a Reporter that stores erroneous files in a script for editing. | ||
| */ | ||
| class EditReporter(settings: Settings) extends Reporter { |
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.
If @lrytz was up for a reporters module, I'd contribute.
| // For that case, check if the root import dealiases to the definition. | ||
| private def resolveAmbiguity(name: Name, defSym: Symbol, impSym: Symbol, imp: ImportInfo): Boolean = { | ||
| defSym == impSym || imp.isRootImport && { | ||
| impSym.isAliasType && impSym.info.typeSymbol.fullName == defSym.fullName |
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.
@retronym Help. I didn't have time to improve this yet.
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'm having trouble paging in the context for this from my mental swap space... could you elaborate a little?
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.
If root import scala._ alias Seq collides with Seq defined in enclosing package, recognize that they are the same. There is related code for when two imports collide.
|
My plan is to re-do this on 2.13 and then add If I compile with If I compile with |
Fixes the implementation of point 4. from SLS chapter 2:
> Definitions made available by a package clause not in the
> compilation unit where the reference occurs have lowest precedence.
We had code to deal with this:
if (defSym.exists && impSym.exists) {
if (isPackageOwnedInDifferentUnit(defSym))
defSym = NoSymbol
But, in the `pos/t2458`, no `impSym` was around, due to filtering
in `depthOk`. The depth of the imported symbol was the same as the
depth of the defined symbol, which didn't pass:
imp.depth > symbolDepth
`depthOk` already had special handling for Java sources: if the
import is non-wildcard and depths are equal, retain the import.
This commit does the same thing for Scala sources, using the
`isPackageOwnedInDifferentUnit` as the criterion. It also makes
the check for the "imported ... is permanently hidden" warning
to avoid the spurious warning.
Fix by retronym
Excavation and preparation of bones for mounting by community
The Java test for explicit import tripped up the Scala test for foreign definition (i.e., in other compilation unit). This commit refactors the boolean expression.
930594a to
1aba572
Compare
|
Rebased with the fix for root imports aka preamble imports. No longer impacts the world like an asteroid. |
This has the form
```
import p._ ; package p { S }
```
where S is both made available in p and also explicitly
imported in enclosing scope.
The code for reconciling ambiguous imports is not
triggered here.
This change allows the package-owned symbols clause to respect nesting depth without breaking all code. This corresponds to the intuition that the implicit imports of the root context, which are not written in source code, do not conflict with user-written imports and definitions.
1aba572 to
c957bcd
Compare
This comment has been minimized.
This comment has been minimized.
|
Gitter is down? so I'll ask here whether this existing behavior seems too loose: I was considering whether the ambiguity in a test class deserves a pass. (Update: Yes, it does, even though the fix (moving import inside packages that need it) is easy. If the import goes unused, the user can ask for a warning.) |
fef604b to
c4c5c88
Compare
Packages and objects can be specified. A source file can exclude imports from one or more objects with the usual mechanism, formerly known as the `Predef` exclusion clause. Handle overloaded foreign definitions: If one alternative is foreign definition, take the overload as foreign definition.
c4c5c88 to
c25bc57
Compare
|
I needed this today.
|
|
I need this basically all the time.
|
|
Moving this to the next 2.13 milestone. |
|
@adriaanm There's a forward port PR for 2.13; I have a |
|
Sure, as a backport once it has landed in 2.13.x. I'm concerned with how thin our attention is spread across the PR queue these days, so I'd like to compact the queue. (It's nice to be so outnumbered, but also regret the delays this is causing.) |
|
Superseded for 2.13 by #6589 |
Fixes the implementation of point 4. from SLS chapter 2:
We had code to deal with this:
if (defSym.exists && impSym.exists) {
if (isPackageOwnedInDifferentUnit(defSym))
defSym = NoSymbol
But, in the
pos/t2458, noimpSymwas around, due to filteringin
depthOk. The depth of the imported symbol was the same as thedepth of the defined symbol, which didn't pass:
imp.depth > symbolDepth
depthOkalready had special handling for Java sources: if theimport is non-wildcard and depths are equal, retain the import.
This commit does the same thing for Scala sources, using the
isPackageOwnedInDifferentUnitas the criterion. It also makesthe check for the "imported ... is permanently hidden" warning
to avoid the spurious warning.
Fix by retronym
Excavation and preparation of bones for mounting by community
Fixes scala/bug#2458
Fixes scala/bug#9552