diff options
author | Paul Phillips <paulp@improving.org> | 2013-04-26 13:31:48 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-04-26 15:57:17 -0700 |
commit | b2c67b328daeaf51eacdb0333db85a7287b5fe1f (patch) | |
tree | 507b4785430fe9d06b4037c7a8c2850ad6cf0511 /test | |
parent | fbb13630d3c1dc9b8fdc503538d4ace5873f31c9 (diff) | |
download | scala-b2c67b328daeaf51eacdb0333db85a7287b5fe1f.tar.gz scala-b2c67b328daeaf51eacdb0333db85a7287b5fe1f.tar.bz2 scala-b2c67b328daeaf51eacdb0333db85a7287b5fe1f.zip |
SI-7398 Add support for java8 default methods
In classfile parser: mark symbols which represent interface
methods yet have code attributes with new flag DEFAULTMETHOD.
These must be kept distinct from regular method bodies so that
an error can be issued when a regular concrete method is
overridden without the override keyword, but not when the
overridden method is a default.
In java source parser: mark Modifiers of interface default
methods with DEFAULTMETHOD flag.
Writing the test was everything I dreamed, and more! However,
% test/partest --debug test/files/run/t7398.scala
Skipping java8-specific test under java version 1.7.0_21
testing: [...]/files/run/t7398.scala [ OK ]
All of 1 tests were successful (elapsed time: 00:00:04)
% test/partest --debug test/files/run/t7398.scala
Attempting java8-specific test under java version 1.8.0-ea
testing: [...]/files/run/t7398.scala [ OK ]
All of 1 tests were successful (elapsed time: 00:00:13)
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/t7398.scala | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/files/run/t7398.scala b/test/files/run/t7398.scala new file mode 100644 index 0000000000..e4090f7db3 --- /dev/null +++ b/test/files/run/t7398.scala @@ -0,0 +1,31 @@ +import scala.tools.partest._ + +object Test extends CompilerTest { + import global._ + + def javaVersion = scala.util.Properties.javaVersion + def isJavaEight = javaVersion startsWith "1.8" + // This way we auto-pass on non-java8 since there's nothing to check + override lazy val units = { + val res: List[CompilationUnit] = if (isJavaEight) javaCompilationUnits(global)(defaultMethodSource) else Nil + val word = if (isJavaEight) "Attempting" else "Skipping" + log(s"$word java8-specific test under java version $javaVersion") + res + } + + private def defaultMethodSource = """ +public interface Iterator<E> { + boolean hasNext(); + E next(); + default void remove() { + throw new UnsupportedOperationException("remove"); + } + default void forEachRemaining(Consumer<? super E> action) { + throw new UnsupportedOperationException("forEachRemaining"); + } +} + """ + + // We're only checking we can parse it. + def check(source: String, unit: global.CompilationUnit): Unit = () +} |