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/config/JavaPlatform.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/config/JavaPlatform.scala')
-rw-r--r-- | src/dotty/tools/dotc/config/JavaPlatform.scala | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/config/JavaPlatform.scala b/src/dotty/tools/dotc/config/JavaPlatform.scala index 432a9a0b7..433b5b3f0 100644 --- a/src/dotty/tools/dotc/config/JavaPlatform.scala +++ b/src/dotty/tools/dotc/config/JavaPlatform.scala @@ -7,6 +7,7 @@ import ClassPath.{ JavaContext, DefaultJavaContext } import core._ import Symbols._, Types._, Contexts._, Denotations._, SymDenotations._, StdNames._, Names._ import Flags._, Scopes._, Decorators._, NameOps._, util.Positions._ +import transform.ExplicitOuter, transform.SymUtils._ class JavaPlatform extends Platform { @@ -38,6 +39,14 @@ class JavaPlatform extends Platform { def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = new ctx.base.loaders.PackageLoader(root, classPath) + /** Is the SAMType `cls` also a SAM under the rules of the JVM? */ + def isSam(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 + /** We could get away with excluding BoxedBooleanClass for the * purpose of equality testing since it need not compare equal * to anything but other booleans, but it should be present in |