diff options
author | Sébastien Doeraene <sjrdoeraene@gmail.com> | 2016-03-05 01:08:18 +0100 |
---|---|---|
committer | Sébastien Doeraene <sjrdoeraene@gmail.com> | 2016-03-07 14:41:36 +0100 |
commit | c14c9c096d09d9e21f1fd4ec27e6b416db01512f (patch) | |
tree | 628838c31d6d2ca6c46bb5591882501cdb608030 /src/dotty/tools/dotc/transform/ExpandSAMs.scala | |
parent | a50926701ef5171779aa025d2d307751d166cabe (diff) | |
download | dotty-c14c9c096d09d9e21f1fd4ec27e6b416db01512f.tar.gz dotty-c14c9c096d09d9e21f1fd4ec27e6b416db01512f.tar.bz2 dotty-c14c9c096d09d9e21f1fd4ec27e6b416db01512f.zip |
Move the logic of ExpandSAMs.isJvmSam to Platform.isSam.
Whether a language SAM type is also a valid SAM type for the
back-end is a platform-specific thing. On Scala.js, for example,
the rules are completely different than for the JVM.
This commit therefore moves the logic of the predicate used by
ExpandSAMs to decide whether to expand a SAM as an anonymous class
to the Platform.
Diffstat (limited to 'src/dotty/tools/dotc/transform/ExpandSAMs.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/ExpandSAMs.scala | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/src/dotty/tools/dotc/transform/ExpandSAMs.scala index 5de778fab..58771734a 100644 --- a/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -25,13 +25,9 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => import ast.tpd._ - /** 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 + /** Is the SAMType `cls` also a SAM under the rules of the platform? */ + def isPlatformSam(cls: ClassSymbol)(implicit ctx: Context): Boolean = + ctx.platform.isSam(cls) 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 => @@ -39,7 +35,7 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => case NoType => tree // it's a plain function case tpe @ SAMType(_) if tpe.isRef(defn.PartialFunctionClass) => toPartialFunction(tree) - case tpe @ SAMType(_) if isJvmSam(tpe.classSymbol.asClass) => + case tpe @ SAMType(_) if isPlatformSam(tpe.classSymbol.asClass) => tree case tpe => cpy.Block(tree)(stats, |