Skip to content

Commit

Permalink
Merge pull request scala#4650 from lrytz/t8502-package
Browse files Browse the repository at this point in the history
SI-8502 create PackageClass instead of Class symbol stubs for pkgs
  • Loading branch information
retronym committed Jul 20, 2015
2 parents 62e915d + b6feac2 commit 0e9525a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/intellij/interactive.iml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
<orderEntry type="module" module-name="library" />
<orderEntry type="module" module-name="reflect" />
<orderEntry type="library" name="starr" level="project" />
<orderEntry type="library" name="asm" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions src/intellij/repl.iml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<orderEntry type="module" module-name="compiler" />
<orderEntry type="module" module-name="library" />
<orderEntry type="module" module-name="reflect" />
<orderEntry type="module" module-name="interactive" />
<orderEntry type="library" name="starr" level="project" />
<orderEntry type="library" name="repl-deps" level="project" />
<orderEntry type="library" name="asm" level="project" />
Expand Down
1 change: 1 addition & 0 deletions src/intellij/scaladoc.iml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<orderEntry type="library" name="scaladoc-deps" level="project" />
<orderEntry type="library" name="ant" level="project" />
<orderEntry type="library" name="partest" level="project" />
<orderEntry type="library" name="asm" level="project" />
</component>
</module>
5 changes: 3 additions & 2 deletions src/reflect/scala/reflect/internal/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* failure to the point when that name is used for something, which is
* often to the point of never.
*/
def newStubSymbol(name: Name, missingMessage: String): Symbol = name match {
case n: TypeName => new StubClassSymbol(this, n, missingMessage)
def newStubSymbol(name: Name, missingMessage: String, isPackage: Boolean = false): Symbol = name match {
case n: TypeName => if (isPackage) new StubPackageClassSymbol(this, n, missingMessage) else new StubClassSymbol(this, n, missingMessage)
case _ => new StubTermSymbol(this, name.toTermName, missingMessage)
}

Expand Down Expand Up @@ -3469,6 +3469,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def companionSymbol = fail(NoSymbol)
}
class StubClassSymbol(owner0: Symbol, name0: TypeName, val missingMessage: String) extends ClassSymbol(owner0, owner0.pos, name0) with StubSymbol
class StubPackageClassSymbol(owner0: Symbol, name0: TypeName, val missingMessage: String) extends PackageClassSymbol(owner0, owner0.pos, name0) with StubSymbol
class StubTermSymbol(owner0: Symbol, name0: TermName, val missingMessage: String) extends TermSymbol(owner0, owner0.pos, name0) with StubSymbol

trait FreeSymbol extends Symbol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ abstract class UnPickler {
val sym = readSymbolRef() match {
case stub: StubSymbol if !stub.isClass =>
// SI-8502 This allows us to create a stub for a unpickled reference to `missingPackage.Foo`.
stub.owner.newStubSymbol(stub.name.toTypeName, stub.missingMessage)
stub.owner.newStubSymbol(stub.name.toTypeName, stub.missingMessage, isPackage = true)
case sym => sym
}
ThisType(sym)
Expand Down
46 changes: 46 additions & 0 deletions test/files/run/t8502b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import scala.tools.partest._
import java.io.File

// used to crash with an assertion failure in flatten because the type symbol created for the missing
// package was a ClassSymbol, not a PackageClassSymbol
// - isFlattenablePrefix(vanishingPackage) was true (wrongly)
// - therefore flatten tried to flatten the class defined in the package, but the class is
// top-level, vanishingClass.enclosingTopLevelClass is NoSymbol
object Test extends StoreReporterDirectTest {
def code = ???

def compileCode(code: String) = {
val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
}

def show(): Unit = {
compileCode("""
class Outer {
class Nested extends vanishing.Vanishing
}
package vanishing {
class Vanishing
}
""")
assert(filteredInfos.isEmpty, filteredInfos)
deletePackage("vanishing")
compileCode("""
class Test {
def f(o: Outer): Outer = o
}
""")
assert(storeReporter.infos.isEmpty, storeReporter.infos.mkString("\n")) // Included a MissingRequirementError before.
}

def deletePackage(name: String) {
val directory = new File(testOutput.path, name)
for (f <- directory.listFiles()) {
assert(f.getName.endsWith(".class"))
assert(f.delete())
}
assert(directory.listFiles().isEmpty)
assert(directory.delete())
}
}

0 comments on commit 0e9525a

Please sign in to comment.