Skip to content

Commit 27bcc4a

Browse files
committed
Fix #5924: don't move static to interfaces
1 parent 844754f commit 27bcc4a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

compiler/src/dotty/tools/dotc/transform/LazyVals.scala

-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
3636

3737
override def changesMembers: Boolean = true // the phase adds lazy val accessors
3838

39-
def transformer: LazyVals = new LazyVals
40-
4139
val containerFlags: FlagSet = Synthetic | Mutable | Lazy
4240
val initFlags: FlagSet = Synthetic | Method
4341

compiler/src/dotty/tools/dotc/transform/MoveStatics.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class MoveStatics extends MiniPhase with SymTransformer {
2424
override def phaseName: String = MoveStatics.name
2525

2626
def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = {
27-
if (sym.hasAnnotation(defn.ScalaStaticAnnot) && sym.owner.is(Flags.Module) && sym.owner.companionClass.exists) {
27+
if (sym.hasAnnotation(defn.ScalaStaticAnnot) && sym.owner.is(Flags.Module) &&
28+
sym.owner.companionClass.exists && !sym.owner.companionClass.is(Flags.Trait)) {
2829
sym.owner.asClass.delete(sym.symbol)
2930
sym.owner.companionClass.asClass.enter(sym.symbol)
3031
val flags = if (sym.is(Flags.Method)) sym.flags else sym.flags | Flags.Mutable
@@ -60,6 +61,7 @@ class MoveStatics extends MiniPhase with SymTransformer {
6061
def move(module: TypeDef, companion: TypeDef): List[Tree] = {
6162
assert(companion ne module)
6263
if (!module.symbol.is(Flags.Module)) move(companion, module)
64+
else if (companion.ne(null) && companion.symbol.is(Flags.Trait)) List(module, companion)
6365
else {
6466
val allMembers =
6567
(if(companion ne null) {companion.rhs.asInstanceOf[Template].body} else Nil) ++

tests/run/i5924.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Matchers {
2+
object Helper
3+
}
4+
5+
object Matchers extends Matchers
6+
7+
object Test {
8+
def main(args: Array[String]): Unit = Matchers
9+
}

0 commit comments

Comments
 (0)