8000 Merge pull request #10988 from tgodzik/fix-package · scala/scala@082a924 · GitHub
[go: up one dir, main page]

Skip to content

Commit 082a924

Browse files
authored
Merge pull request #10988 from tgodzik/fix-package
Ensure package objects are opened after namer in interactive
2 parents a74d868 + c6b1879 commit 082a924

File tree

9 files changed

+136
-22
lines changed

9 files changed

+136
-22
lines changed

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
8282
def findMemberFromRoot(fullName: Name): Symbol = rootMirror.findMemberFromRoot(fullName)
8383

8484
override def openPackageModule(pkgClass: Symbol, force: Boolean): Unit = {
85-
if (force || isPast(currentRun.namerPhase)) super.openPackageModule(pkgClass, force = true)
85+
// presentation compiler uses `compileLate` whioch doesn't advance `globalPhase`, so `isPast` is false.
86+
// therefore checking `isAtPhaseAfter` as well.
87+
val forceNow = force || isPast(currentRun.namerPhase) || isRunGlobalInitialized && isAtPhaseAfter(currentRun.namerPhase)
88+
if (forceNow) super.openPackageModule(pkgClass, force = true)
8689
else analyzer.packageObjects.deferredOpen.addOne(pkgClass)
8790
}
88-
8991
// alternate constructors ------------------------------------------
9092

9193
override def settings = currentSettings
@@ -1037,25 +1039,16 @@ class Global(var currentSettings: Settings, reporter0: Reporter)
10371039
private[this] var curFreshNameCreator: FreshNameCreator = null
10381040
private[scala] def currentFreshNameCreator_=(fresh: FreshNameCreator): Unit = curFreshNameCreator = fresh
10391041

1040-
def isGlobalInitialized = (
1041-
definitions.isDefinitionsInitialized
1042-
&& rootMirror.isMirrorInitialized
1043-
)
1042+
def isGlobalInitialized = definitions.isDefinitionsInitialized && rootMirror.isMirrorInitialized
1043+
private def isRunGlobalInitialized = (curRun ne null) && isGlobalInitialized
1044+
10441045
override def isPastTyper = isPast(currentRun.typerPhase)
10451046
def isBeforeErasure = isBefore(currentRun.erasurePhase)
1046-
def isPast(phase: Phase) = (
1047-
(curRun ne null)
1048-
&& isGlobalInitialized // defense against init order issues
1049-
&& (globalPhase.id > phase.id)
1050-
)
1051-
def isBefore(phase: Phase) = (
1052-
(curRun ne null)
1053-
&& isGlobalInitialized // defense against init order issues
1054-
&& (phase match {
1055-
case NoPhase => true // if phase is NoPhase then that phase ain't comin', so we're "before it"
1056-
case _ => globalPhase.id < phase.id
1057-
})
1058-
)
1047+
def isPast(phase: Phase) = isRunGlobalInitialized && (globalPhase.id > phase.id)
1048+
def isBefore(phase: Phase) = isRunGlobalInitialized && (phase match {
1049+
case NoPhase => true // if phase is NoPhase then that phase ain't comin', so we're "before it"
1050+
case _ => globalPhase.id < phase.id
1051+
})
10591052

10601053
// TODO - trim these to the absolute minimum.
10611054
@inline final def exitingErasure[T](op: => T): T = exitingPhase(currentRun.erasurePhase)(op)

src/interactive/scala/tools/nsc/interactive/Global.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
403403
case unit: RichCompilationUnit => unit.isParsed
404404
case _ => true
405405
})
406-
if (isPastNamer) super.openPackageModule(pkgClass, force = true)
407-
else analyzer.packageObjects.deferredOpen.add(pkgClass)
406+
super.openPackageModule(pkgClass, force = isPastNamer)
408407
}
409408

410409
// ----------------- Polling ---------------------------------------

src/interactive/scala/tools/nsc/interactive/tests/InteractiveTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ abstract class InteractiveTest
8686
loadSources()
8787
runDefaultTests()
8888
}
89-
}.linesIterator.map(normalize).foreach(println)
89+
}.linesIterator.filterNot(filterOutLines).map(normalize).foreach(println)
9090
}
9191

92+
protected def filterOutLines(line: String) = false
9293
protected def normalize(s: String) = s
9394

9495
/** Load all sources before executing the test. */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
reload: Main.scala
2+
3+
askTypeCompletion at Main.scala(7,6)
4+
================================================================================
5+
[response] askTypeCompletion at (7,6)
6+
def +(other: String): String
7+
def ->[B](y: B): (concurrent.ExecutionException, B)
8+
def ensuring(cond: Boolean): concurrent.ExecutionException
9+
def ensuring(cond: Boolean, msg: => Any): concurrent.ExecutionException
10+
def ensuring(cond: concurrent.ExecutionException => Boolean): concurrent.ExecutionException
11+
def ensuring(cond: concurrent.ExecutionException => Boolean, msg: => Any): concurrent.ExecutionException
12+
def equals(x$1: Object): Boolean
13+
def fillInStackTrace(): Throwable
14+
def formatted(fmtstr: String): String
15+
def getCause(): Throwable
16+
def getLocalizedMessage(): String
17+
def getMessage(): String
18+
def getStackTrace(): Array[StackTraceElement]
19+
def hashCode(): Int
20+
def initCause(x$1: Throwable): Throwable
21+
def printStackTrace(): Unit
22+
def printStackTrace(x$1: java.io.PrintStream): Unit
23+
def printStackTrace(x$1: java.io.PrintWriter): Unit
24+
def setStackTrace(x$1: Array[StackTraceElement]): Unit
25+
def toString(): String
26+
def →[B](y: B): (concurrent.ExecutionException, B)
27+
final def !=(x$1: Any): Boolean
28+
final def ## : Int
29+
final def ==(x$1: Any): Boolean
30+
final def addSuppressed(x$1: Throwable): Unit
31+
final def asInstanceOf[T0]: T0
32+
final def eq(x$1: AnyRef): Boolean
33+
final def getSuppressed(): Array[Throwable]
34+
final def isInstanceOf[T0]: Boolean
35+
final def ne(x$1: AnyRef): Boolean
36+
final def notify(): Unit
37+
final def notifyAll(): Unit
38+
final def synchronized[T0](x$1: T0): T0
39+
final def wait(): Unit
40+
final def wait(x$1: Long): Unit
41+
final def wait(x$1: Long, x$2: Int): Unit
42+
================================================================================
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.tools.nsc.interactive.tests.InteractiveTest
2+
3+
object Test extends InteractiveTest {
4+
5+
override protected def filterOutLines(line: String) =
6+
line.contains("inaccessible") || line.contains("retrieved ")
7+
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package scala.concurrent
2+
3+
import scala.concurrent.ExecutionException
4+
5+
object Main extends App {
6+
def foo(n: ExecutionException, k: Int): Unit = {
7+
n./*!*/
8+
k
9+
}
10+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
reload: Main.scala
2+
3+
askTypeCompletion at Main.scala(7,6)
4+
================================================================================
5+
[response] askTypeCompletion at (7,6)
6+
def +(other: String): String
7+
def ->[B](y: B): (concurrent.ExecutionException, B)
8+
def ensuring(cond: Boolean): concurrent.ExecutionException
9+
def ensuring(cond: Boolean, msg: => Any): concurrent.ExecutionException
10+
def ensuring(cond: concurrent.ExecutionException => Boolean): concurrent.ExecutionException
11+
def ensuring(cond: concurrent.ExecutionException => Boolean, msg: => Any): concurrent.ExecutionException
12+
def equals(x$1: Object): Boolean
13+
def fillInStackTrace(): Throwable
14+
def formatted(fmtstr: String): String
15+
def getCause(): Throwable
16+
def getLocalizedMessage(): String
17+
def getMessage(): String
18+
def getStackTrace(): Array[StackTraceElement]
19+
def hashCode(): Int
20+
def initCause(x$1: Throwable): Throwable
21+
def printStackTrace(): Unit
22+
def printStackTrace(x$1: java.io.PrintStream): Unit
23+
def printStackTrace(x$1: java.io.PrintWriter): Unit
24+
def setStackTrace(x$1: Array[StackTraceElement]): Unit
25+
def toString(): String
26+
def →[B](y: B): (concurrent.ExecutionException, B)
27+
final def !=(x$1: Any): Boolean
28+
final def ## : Int
29+
final def ==(x$1: Any): Boolean
30+
final def addSuppressed(x$1: Throwable): Unit
31+
final def asInstanceOf[T0]: T0
32+
final def eq(x$1: AnyRef): Boolean
33+
final def getSuppressed(): Array[Throwable]
34+
final def isInstanceOf[T0]: Boolean
35+
final def ne(x$1: AnyRef): Boolean
36+
final def notify(): Unit
37+
final def notifyAll(): Unit
38+
final def synchronized[T0](x$1: T0): T0
39+
final def wait(): Unit
40+
final def wait(x$1: Long): Unit
41+
final def wait(x$1: Long, x$2: Int): Unit
42+
================================================================================
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.tools.nsc.interactive.tests.InteractiveTest
2+
import scala.tools.nsc.util
3+
4+
object Test extends InteractiveTest {
5+
6+
override protected def filterOutLines(line: String) =
7+
line.contains("inaccessible") || line.contains("retrieved ")
8+
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package example
2+
3+
import scala.concurrent.ExecutionException
4+
5+
object Main extends App {
6+
def foo(n: ExecutionException, k: Int): Unit = {
7+
n./*!*/
8+
k
9+
}
10+
}

0 commit comments

Comments
 (0)
0