Skip to content

Commit d25497a

Browse files
committed
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.
1 parent bb94056 commit d25497a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/dotty/tools/dotc/transform/ExpandSAMs.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,19 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer =>
2525

2626
import ast.tpd._
2727

28-
def noJvmSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
29-
!cls.is(Trait) ||
30-
cls.superClass != defn.ObjectClass ||
31-
!cls.is(NoInits) ||
32-
!cls.directlyInheritedTraits.forall(_.is(NoInits)) ||
33-
ExplicitOuter.needsOuterIfReferenced(cls) ||
34-
cls.typeRef.fields.nonEmpty // Superaccessors already show up as abstract methods here, so no test necessary
35-
28+
/** Is SAMType `cls` also a SAM under the rules of the JVM? */
29+
def isJvmSam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
30+
cls.is(NoInitsTrait) &&
31+
cls.superClass == defn.ObjectClass &&
32+
cls.directlyInheritedTraits.forall(_.is(NoInits)) &&
33+
!ExplicitOuter.needsOuterIfReferenced(cls) &&
34+
cls.typeRef.fields.isEmpty // Superaccessors already show up as abstract methods here, so no test necessary
3635

3736
override def transformBlock(tree: Block)(implicit ctx: Context, info: TransformerInfo): Tree = tree match {
3837
case Block(stats @ (fn: DefDef) :: Nil, Closure(_, fnRef, tpt)) if fnRef.symbol == fn.symbol =>
3938
tpt.tpe match {
4039
case NoType => tree // it's a plain function
41-
case tpe @ SAMType(_) if !noJvmSam(tpe.classSymbol.asClass) =>
40+
case tpe @ SAMType(_) if isJvmSam(tpe.classSymbol.asClass) =>
4241
if (tpe isRef defn.PartialFunctionClass) toPartialFunction(tree)
4342
else tree
4443
case tpe =>

0 commit comments

Comments
 (0)