summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/Erasure.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2016-03-29 19:25:06 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-03-29 23:09:39 -0700
commit62d97d7f110894a0c2f36b1ed9dd7ad59c0115fa (patch)
tree084f8abe0d8dea5165e03289870dc8d6adeea6bc /src/compiler/scala/tools/nsc/transform/Erasure.scala
parent63f017586f31de11bc6004dca7cea0c26ceb5ff5 (diff)
downloadscala-62d97d7f110894a0c2f36b1ed9dd7ad59c0115fa.tar.gz
scala-62d97d7f110894a0c2f36b1ed9dd7ad59c0115fa.tar.bz2
scala-62d97d7f110894a0c2f36b1ed9dd7ad59c0115fa.zip
LMF cannot run trait's "initializer" (constructor)
Thus, rule out traits that have a constructor (which we use as a proxy for having potentially side-effecting statements), and create an anonymous subclass for them at compile time.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/Erasure.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index cdf3e18b5a..ebb55afca9 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -1213,6 +1213,10 @@ abstract class Erasure extends AddInterfaces
// When we delay sam expansion until after explicit outer & lambda lift, we could decide there whether
// to expand sam at compile time or use LMF, and this implementation restriction could be lifted.
sym.isStatic &&
+ // HACK: this is to rule out traits with an effectful initializer.
+ // The constructor only exists if the trait's template has statements.
+ // Sadly, we can't be more precise without access to the tree that defines the SAM's owner.
+ !sym.primaryConstructor.exists &&
(sym.isInterface || sym.info.decls.forall(mem => mem.isMethod || mem.isType)) // TODO OPT: && {sym setFlag INTERFACE; true})
// we still need to check our ancestors even if the INTERFACE flag is set, as it doesn't take inheritance into account