-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Delay package object decls entering to the package object phase #9661
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
Merged
dwijnand
merged 6 commits into
scala:2.13.x
from
dwijnand:package-object-with-source-parent-cleaned-up
Jul 9, 2021
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a5d03cd
Delay package object decls entering to the package object phase
retronym 519fbd3
Tests that require lazier loading of package.class
retronym 078f85e
Add test for progression in compiler determism
retronym b7c6d59
progression test: error stale reference inherited package object member
retronym baa9ff8
Remove workaround for scala/bug#5954
retronym 8a15b1c
Test & change package module deferred opening setup
dwijnand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import scala.reflect.io.Path | ||
import scala.tools.partest._ | ||
import java.io.File | ||
|
||
object Test extends StoreReporterDirectTest { | ||
class V1 { | ||
def pkg = "package object b extends B" | ||
def B = "package b; class B { def stale = 42 }" | ||
def A = "package b; class A { stale }" | ||
} | ||
class V2 extends V1 { | ||
override def B = "package b; class B { }" | ||
} | ||
|
||
override def extraSettings = s"-cp ${sys.props("partest.lib")}${File.pathSeparator}$testOutput" | ||
|
||
def show(): Unit = { | ||
val v1 = new V1 | ||
val v2 = new V2 | ||
compiles(v1.A, v1.B, v1.pkg)() | ||
delete(testOutput / "b" / "A.class") | ||
compiles(v2.B, v2.A)(Some("not found: value stale")) | ||
} | ||
|
||
def compiles(codes: String*)(expectedError: Option[String] = None) = { | ||
val global = newCompiler() | ||
withRun(global)(_ compileSources newSources(codes: _*)) | ||
val reporterOutput = storeReporter.infos.map(x => x.pos.showError(x.msg)).mkString("\n") | ||
expectedError match { | ||
case None => | ||
assert(!global.reporter.hasErrors, reporterOutput) | ||
case Some(text) => | ||
assert(global.reporter.hasErrors, "expected compile failure, got success") | ||
assert(reporterOutput.contains(text), reporterOutput) | ||
} | ||
} | ||
|
||
def delete(paths: Path*) = paths.foreach(p => assert(p.delete(), s"$p didn't delete")) | ||
def code = "" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import java.io.File | ||
import java.net.URLClassLoader | ||
|
||
import scala.reflect.io.Path | ||
import scala.reflect.runtime.{ universe => ru } | ||
import scala.tools.partest._ | ||
import scala.tools.reflect.ToolBox | ||
|
||
import org.junit.Assert._ | ||
|
||
object Test extends StoreReporterDirectTest { | ||
val cp = List(sys.props("partest.lib"), testOutput.path) | ||
override def extraSettings = s"-cp ${cp.mkString(File.pathSeparator)}" | ||
|
||
def show(): Unit = { | ||
compiles("package object pkg { def foo = 1 }") | ||
val loader = new URLClassLoader(cp.map(new File(_).toURI.toURL).toArray) | ||
val mirror = ru.runtimeMirror(loader) | ||
|
||
val toolbox = mirror.mkToolBox() | ||
val result1 = toolbox.eval(toolbox.parse("pkg.foo")) | ||
assertEquals(1, result1) | ||
|
||
val obj = toolbox.eval(toolbox.parse("pkg.`package`")) | ||
val pkg = mirror.staticPackage("pkg") | ||
val sym = pkg.info.decl(ru.TermName("foo")).asMethod | ||
val meth = mirror.reflect(obj).reflectMethod(sym) | ||
val res2 = meth.apply() | ||
assertEquals(1, res2) | ||
} | ||
|
||
def compiles(codes: String*) = { | ||
val global = newCompiler() | ||
withRun(global)(_ compileSources newSources(codes: _*)) | ||
assert(!global.reporter.hasErrors, storeReporter.infos.mkString("\n")) | ||
} | ||
|
||
def delete(paths: Path*) = paths.foreach(p => assert(p.delete(), s"$p didn't delete")) | ||
def code = "" | ||
} |
25 changes: 25 additions & 0 deletions
25
test/files/run/package-object-with-inner-class-in-ancestor-simpler-still.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import scala.reflect.io.Path | ||
import scala.tools.partest._ | ||
import java.io.File | ||
|
||
object Test extends StoreReporterDirectTest { | ||
def A = "package b; class A" | ||
def pkg = "package object b extends A" | ||
|
||
override def extraSettings = s"-cp ${sys.props("partest.lib")}${File.pathSeparator}$testOutput" | ||
|
||
def show(): Unit = { | ||
compiles(A, pkg) | ||
delete(testOutput / "b" / "A.class") | ||
compiles(A) | ||
} | ||
|
||
def compiles(codes: String*) = { | ||
val global = newCompiler() | ||
withRun(global)(_ compileSources newSources(codes: _*)) | ||
assert(!global.reporter.hasErrors, storeReporter.infos.mkString("\n")) | ||
} | ||
|
||
def delete(paths: Path*) = paths.foreach(p => assert(p.delete(), s"$p didn't delete")) | ||
def code = "" | ||
} |
26 changes: 26 additions & 0 deletions
26
test/files/run/package-object-with-inner-class-in-ancestor-simpler.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import scala.reflect.io.Path | ||
import scala.tools.partest._ | ||
import java.io.File | ||
|
||
object Test extends StoreReporterDirectTest { | ||
def A = "package b; class A" | ||
def pkg = "package object b extends A" | ||
def M = "package b; class M" | ||
|
||
override def extraSettings = s"-cp ${sys.props("partest.lib")}${File.pathSeparator}$testOutput" | ||
|
||
def show(): Unit = { | ||
compiles(A, pkg, M) | ||
delete(testOutput / "b" / "A.class") | ||
compiles(M, A) | ||
} | ||
|
||
def compiles(codes: String*) = { | ||
val global = newCompiler() | ||
withRun(global)(_ compileSources newSources(codes: _*)) | ||
assert(!global.reporter.hasErrors, storeReporter.infos.mkString("\n")) | ||
} | ||
|
||
def delete(paths: Path*) = paths.foreach(p => assert(p.delete(), s"$p didn't delete")) | ||
def code = "" | ||
} |
33 changes: 33 additions & 0 deletions
33
test/files/run/package-object-with-inner-class-in-ancestor.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import scala.reflect.io.Path | ||
import scala.tools.partest._ | ||
import java.io.File | ||
|
||
object Test extends StoreReporterDirectTest { | ||
class V1 { | ||
def O = "package b; object O { def o = \"\" }" | ||
def A = "package b; class A { class C { O.o } }" | ||
def pkg = "package object b extends A" | ||
} | ||
class V2 extends V1 { | ||
override def O = "package b; object O { def o = 42 }" | ||
} | ||
|
||
override def extraSettings = s"-cp ${sys.props("partest.lib")}${File.pathSeparator}$testOutput" | ||
|
||
def show(): Unit = { | ||
val v1 = new V1 | ||
compiles(v1.O, v1.A, v1.pkg) | ||
delete(testOutput / "b" / "A.class", testOutput / "b" / "A$C.class") | ||
val v2 = new V2 | ||
compiles(v2.O, v2.A) | ||
} | ||
|
||
def compiles(codes: String*) = { | ||
val global = newCompiler() | ||
withRun(global)(_ compileSources newSources(codes: _*)) | ||
assert(!global.reporter.hasErrors, storeReporter.infos.mkString("\n")) | ||
} | ||
|
||
def delete(paths: Path*) = paths.foreach(p => assert(p.delete(), s"$p didn't delete")) | ||
def code = "" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.