Skip to content

Commit c7e71b8

Browse files
committed
Surive non-existing sourceModule in Scala2 pickled info.
It seems when unpickling nsc that some module classes come without a source module. Survive this situation rather than crashing. i859.scala is an example. i859 compiles with the patch, but causes a deep subtype when unpickling. Not sure whether scalac does the same.
1 parent 041d42f commit c7e71b8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ object Scala2Unpickler {
101101
case cinfo => (Nil, cinfo)
102102
}
103103
val ost =
104-
if ((selfInfo eq NoType) && (denot is ModuleClass))
104+
if ((selfInfo eq NoType) && (denot is ModuleClass) && denot.sourceModule.exists)
105+
// it seems sometimes the source module does not exist for a module class.
106+
// An example is `scala.reflect.internal.Trees.Template$. Without the
107+
// `denot.sourceModule.exists` provision i859.scala crashes in the backend.
105108
denot.owner.thisType select denot.sourceModule
106109
else selfInfo
107-
108110
denot.info = ClassInfo(denot.owner.thisType, denot.classSymbol, Nil, decls, ost) // first rough info to avoid CyclicReferences
109111
var parentRefs = ctx.normalizeToClassRefs(parents, cls, decls)
110112
if (parentRefs.isEmpty) parentRefs = defn.ObjectType :: Nil

test/dotc/tests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class tests extends CompilerTest {
103103

104104
@Test def pos_i871 = compileFile(posSpecialDir, "i871", scala2mode)
105105
@Test def pos_variancesConstr = compileFile(posSpecialDir, "variances-constr", scala2mode)
106+
@Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes)
106107

107108
@Test def new_all = compileFiles(newDir, twice)
108109

tests/pos-special/i859.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Analyzer {
2+
def foo: scala.tools.nsc.Global = ???
3+
}

0 commit comments

Comments
 (0)