Skip to content

Mixin: fix the initialization of traits #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/transform/Mixin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>

def traitDefs(stats: List[Tree]): List[Tree] = {
val initBuf = new mutable.ListBuffer[Tree]
stats flatMap {
stats.flatMap({
case stat: DefDef if stat.symbol.isGetter && !stat.rhs.isEmpty && !stat.symbol.is(Flags.Lazy) =>
// make initializer that has all effects of previous getter,
// replace getter rhs with empty tree.
Expand All @@ -114,7 +114,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform =>
case stat =>
initBuf += stat
Nil
}
}) ++ initBuf
}

def transformSuper(tree: Tree): Tree = {
Expand Down
2 changes: 2 additions & 0 deletions tests/run/traitInit.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello
World
13 changes: 13 additions & 0 deletions tests/run/traitInit.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trait Hello {
println("Hello")
val x: Int = 1
println("World")
}

class A extends Hello

object Test {
def main(args: Array[String]): Unit = {
new A
}
}