diff options
author | Martin Odersky <odersky@gmail.com> | 2015-06-16 15:02:22 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2015-06-16 16:42:54 +0200 |
commit | d25497a92f425c8966dce47cd17fba456ef2660f (patch) | |
tree | 7168598edac4f5a13e174052257e16af9a98d65c | |
parent | bb940560529ba460af4caa967caaa7f34f944b04 (diff) | |
download | dotty-d25497a92f425c8966dce47cd17fba456ef2660f.tar.gz dotty-d25497a92f425c8966dce47cd17fba456ef2660f.tar.bz2 dotty-d25497a92f425c8966dce47cd17fba456ef2660f.zip |
Avoid double negation in isJvmSam.
Found while trying to chase down the problem with stale symbols in last commit. Double negation
is confusing. The new formulation avoids it.
-rw-r--r-- | src/dotty/tools/dotc/transform/ExpandSAMs.scala | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/src/dotty/tools/dotc/transform/ExpandSAMs.scala index 2416e4624..1650a244d 100644 --- a/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -25,20 +25,19 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => import ast.tpd._ - def noJvmSam(cls: ClassSymbol)(implicit ctx: Context): Boolean = - !cls.is(Trait) || - cls.superClass != defn.ObjectClass || - !cls.is(NoInits) || - !cls.directlyInheritedTraits.forall(_.is(NoInits)) || - ExplicitOuter.needsOuterIfReferenced(cls) || - cls.typeRef.fields.nonEmpty // Superaccessors already show up as abstract methods here, so no test necessary - + /** Is SAMType `cls` also a SAM under the rules of the JVM? */ + def isJvmSam(cls: ClassSymbol)(implicit ctx: Context): Boolean = + cls.is(NoInitsTrait) && + cls.superClass == defn.ObjectClass && + cls.directlyInheritedTraits.forall(_.is(NoInits)) && + !ExplicitOuter.needsOuterIfReferenced(cls) && + cls.typeRef.fields.isEmpty // Superaccessors already show up as abstract methods here, so no test necessary override def transformBlock(tree: Block)(implicit ctx: Context, info: TransformerInfo): Tree = tree match { case Block(stats @ (fn: DefDef) :: Nil, Closure(_, fnRef, tpt)) if fnRef.symbol == fn.symbol => tpt.tpe match { case NoType => tree // it's a plain function - case tpe @ SAMType(_) if !noJvmSam(tpe.classSymbol.asClass) => + case tpe @ SAMType(_) if isJvmSam(tpe.classSymbol.asClass) => if (tpe isRef defn.PartialFunctionClass) toPartialFunction(tree) else tree case tpe => |