diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-05-16 22:43:53 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2015-05-21 16:29:28 +0200 |
commit | c48badad54f90047f690d02e8af80153c6634412 (patch) | |
tree | 6a0de36f10b33f618203775254460d380982e486 /src | |
parent | bf81fb62084f9e04e43906396c3ac5e307caca63 (diff) | |
download | dotty-c48badad54f90047f690d02e8af80153c6634412.tar.gz dotty-c48badad54f90047f690d02e8af80153c6634412.tar.bz2 dotty-c48badad54f90047f690d02e8af80153c6634412.zip |
Mixin: fix the initialization of traits
Before this commit, the following code:
trait Hello {
println("Hello")
val x: Int = 1
println("World")
}
Became:
<trait> trait Hello extends Object {
def <init>(): Hello = {
{
()
}
this
}
<accessor> def x(): Int
protected def initial$x(): Int = {
println("Hello")
1
}
}
Notice that the initialization statements after the last getter were
missing, this is now fixed:
<trait> trait Hello extends Object {
def <init>(): Hello = {
{
println("World")
()
}
this
}
<accessor> def x(): Int
protected def initial$x(): Int = {
println("Hello")
1
}
}
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/transform/Mixin.scala | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/transform/Mixin.scala b/src/dotty/tools/dotc/transform/Mixin.scala index e6e2ad259..8470be2ef 100644 --- a/src/dotty/tools/dotc/transform/Mixin.scala +++ b/src/dotty/tools/dotc/transform/Mixin.scala @@ -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. @@ -114,7 +114,7 @@ class Mixin extends MiniPhaseTransform with SymTransformer { thisTransform => case stat => initBuf += stat Nil - } + }) ++ initBuf } def transformSuper(tree: Tree): Tree = { |