-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Ensure package objects are opened after namer in interactive #10988
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
I am not 100% about the fix, but I got kind of lost in what is going on there. We seem to have two Maybe it's connected to the lazy analyser in interactive.Global that overrides the other lazy analyser? I am not sure about how that could be involved. |
Looks like this should have been a part of #9661 since it makes sense in terms of:
|
@@ -80,7 +80,7 @@ trait Analyzer extends AnyRef | |||
|
|||
def apply(unit: CompilationUnit): Unit = { | |||
openPackageObjectsTraverser(unit.body) | |||
deferredOpen.foreach(openPackageModule(_)) | |||
deferredOpen.foreach(openPackageModule(_, force = true)) |
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.
What's confusing: this change is in the packageobjects
phase, which is after namer.
openPackageModule
checks isPast(currentRun.namerPhase)
, so it should not delay opening.
but isPast
compares with globalPhase
, and it turns out that in this case we get here through compileLate
, which only sets phase
but not globalPhase
.
at scala.tools.nsc.typechecker.Analyzer$packageObjects$$anon$2.apply(Analyzer.scala:84)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:483)
at scala.tools.nsc.Global$Run.$anonfun$compileLate$3(Global.scala:1703)
...
at scala.tools.nsc.Global$Run.compileLate(Global.scala:1702)
at scala.tools.nsc.interactive.Global.parseAndEnter(Global.scala:669)
so yeah, i think this looks right. it should not ever make a difference in batch compilation.
note that there is already some logic in interactive.Global.openPackageModule
to set force = true
in more cases, but that doesn't fire here either (unit.isParsed
is 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.
ha, a brief line comment would be nice. // globalPhase may not be past namer when compileLate
. I looked briefly last night and knew I was missing something.
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.
Added! Let me know if the comment is enough
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.
running sbt:scala2> partest test/files/presentation/package-object-issues
locally i get a difference:
!! 1 - presentation/package-object-issues [output differs]
% diff /Users/luc/code/scala/scala13/test/files/presentation/package-object-issues.check /Users/luc/code/scala/scala13/test/files/presentation/package-object-issues-presentation.log
@@ -3,9 +3,8 @@ reload: Main.scala
askTypeCompletion at Main.scala(7,6)
================================================================================
[response] askTypeCompletion at (7,6)
-retrieved 46 members
-[inaccessible] private[package lang] def getStackTraceDepth(): Int
-[inaccessible] private[package lang] def getStackTraceElement(x$1: Int): StackTraceElement
+retrieved 45 members
+[inaccessible] final private[package lang] def setCause(x$1: Throwable): Unit
[inaccessible] protected[package lang] def clone(): Object
[inaccessible] protected[package lang] def finalize(): Unit
def +(other: String): String
can you explain this? maybe it depends on the java version? i'm on 21.0.1+12-LTS
.
Yes, I had the same on JDK 21. I am not 100% sure why it's different, but I don't think it has anything to do with the fixed bug. We would probably get the same if a normal import. |
I added a similar case without the scala.concurrent package and the result is the same. |
I found my old branch, but I don't remember how the tests work. I'll report on it below. I got this test to work by changing the pres global to always delegate:
and
My printlns indicate that pres Global defers the package, then package objects (PO) dequeues them and pres Global's
in the working case, nsc Global correctly decides to force based on
My test had the package object source in the test dir, not in src. But it works trivially if it is in the src dir. So I don't know yet how the test is structured, or I've long forgotten.
|
The problem is that this will fail CI after merge. PR validation is on JDK 8 only, but after merging we test on many JDKs. |
@som-snytt I agree the change to
yeah, probably that is the more principled fix. a bit unfortunate we have manually check global initialization. but not unexpected as we're in this difficult area of forcing things not too early, but also not too late... I pushed those changes. |
76c3724
to
9ef1368
Compare
Package objects need to be opened during the packageobjects phase. This was not happening in presentation compilation because the phase check looks at `globalPhase`, but in presentation compilation (completion) the code is processed through `compileLate` which only advances the SymbolTable phase.
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, thanks!
Squashed.
Package objects need to be opened during the packageobjects
phase. This was not happening in presentation compilation
because the phase check looks at
globalPhase
, but in presentationcompilation (completion) the code is processed through
compileLate
which only advances the SymbolTable phase.
Fixes scala/bug#12663