Skip to content

Commit 6a472bf

Browse files
committed
Fix RestoreScopes from destroying companion links.
Fixes #476
1 parent 4b1dd78 commit 6a472bf

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/dotty/tools/dotc/transform/RestoreScopes.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ast.Trees._
1313
import NameOps._
1414
import typer.Mode
1515
import TreeTransforms.TransformerInfo
16+
import StdNames._
1617

1718
/** The preceding lambda lift and flatten phases move symbols to different scopes
1819
* and rename them. This miniphase cleans up afterwards and makes sure that all
@@ -33,6 +34,19 @@ class RestoreScopes extends MiniPhaseTransform with IdentityDenotTransformer { t
3334
// For top-level classes this does nothing.
3435
val cls = tree.symbol.asClass
3536
val pkg = cls.owner.asClass
37+
38+
// Bring back companion links
39+
val companionClass = cls.info.decls.lookup(nme.COMPANION_CLASS_METHOD)
40+
val companionModule = cls.info.decls.lookup(nme.COMPANION_MODULE_METHOD)
41+
42+
if (companionClass.exists) {
43+
restoredDecls.enter(companionClass)
44+
}
45+
46+
if (companionModule.exists) {
47+
restoredDecls.enter(companionModule)
48+
}
49+
3650
pkg.enter(cls)
3751
val cinfo = cls.classInfo
3852
tree.symbol.copySymDenotation(

0 commit comments

Comments
 (0)