Skip to content

Commit 2ba6774

Browse files
committed
SI-5756 correctly reifies local module classes
Unlike module classes that are going to be pickled (which are reified as `<their module reification>.moduleClass), module classes of local modules need to be reified as symbol defs. Otherwise we get a stack overflow: 1) Local modules are deemed to be free terms, 2) All free symbols are reified together with their type signature (so that they can be a) inspected by anyone interested, b) compiled at runtime), 3) Reifying a type signature of a module involves reifying its module class, 4) Reifying a module class involves reifying a module and calling its module class, <ad infinitum> This stack overflow doesn't happen for locatable modules, because they don't need to have their type signatures reified (these signatures can later be loaded from pickles if it becomes necessary).
1 parent 1183f06 commit 2ba6774

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/compiler/scala/reflect/reify/codegen/GenSymbols.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ trait GenSymbols {
3636
else if (sym.isEmptyPackageClass)
3737
mirrorMirrorSelect(nme.EmptyPackageClass)
3838
else if (sym.isModuleClass)
39-
Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass)
39+
if (sym.sourceModule.isLocatable) Select(Select(reify(sym.sourceModule), nme.asModule), nme.moduleClass)
40+
else reifySymDef(sym)
4041
else if (sym.isPackage)
4142
mirrorMirrorCall(nme.staticPackage, reify(sym.fullName))
4243
else if (sym.isLocatable) {

test/files/pos/t5756.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import scala.reflect.runtime.universe._
2+
3+
object Test extends App {
4+
def tagme[T: TypeTag](x: T) = typeTag[T]
5+
val foo = tagme{object Bar; Bar}
6+
}

test/files/pos/t6204-a.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.reflect.runtime.universe._
2+
3+
object Bish {
4+
def m {
5+
object Bash {
6+
typeOf[Option[_]]
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)