From 77b8b6a11fbcb067160052a54b9d777593787fb5 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Wed, 15 Jul 2015 19:59:57 +0200 Subject: SI-9393 fix modifiers of ClassBTypes for Java annotations The Scala classfile and java source parsers make Java annotation classes (which are actually interfaces at the classfile level) look like Scala annotation classes: - the INTERFACE / ABSTRACT flags are not added - scala.annotation.Annotation is added as superclass - scala.annotation.ClassfileAnnotation is added as interface This makes type-checking @Annot uniform, whether it is defined in Java or Scala. This is a hack that leads to various bugs (SI-9393, SI-9400). Instead the type-checking should be special-cased for Java annotations. This commit fixes SI-9393 and a part of SI-9400, but it's still easy to generate invalid classfiles. Restores the assertions that were disabled in #4621. I'd like to leave these assertions in: they are valuable and helped uncovering the issue being fixed here. A new flag JAVA_ANNOTATION is introduced for Java annotation ClassSymbols, similar to the existing ENUM flag. When building ClassBTypes for Java annotations, the flags, superclass and interfaces are recovered to represent the situation in the classfile. Cleans up and documents the flags space in the area of "late" and "anti" flags. The test for SI-9393 is extended to test both the classfile and the java source parser. --- test/files/pos/t9393/Named.java | 3 --- test/files/pos/t9393/NamedImpl.java | 15 --------------- test/files/pos/t9393/NamedImpl_1.java | 15 +++++++++++++++ test/files/pos/t9393/NamedImpl_2.java | 15 +++++++++++++++ test/files/pos/t9393/Named_1.java | 3 +++ test/files/pos/t9393/Named_2.java | 3 +++ test/files/pos/t9393/test.scala | 3 --- test/files/pos/t9393/test_2.scala | 4 ++++ 8 files changed, 40 insertions(+), 21 deletions(-) delete mode 100644 test/files/pos/t9393/Named.java delete mode 100644 test/files/pos/t9393/NamedImpl.java create mode 100644 test/files/pos/t9393/NamedImpl_1.java create mode 100644 test/files/pos/t9393/NamedImpl_2.java create mode 100644 test/files/pos/t9393/Named_1.java create mode 100644 test/files/pos/t9393/Named_2.java delete mode 100644 test/files/pos/t9393/test.scala create mode 100644 test/files/pos/t9393/test_2.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t9393/Named.java b/test/files/pos/t9393/Named.java deleted file mode 100644 index 144ddbf26e..0000000000 --- a/test/files/pos/t9393/Named.java +++ /dev/null @@ -1,3 +0,0 @@ -package bug; - -public @interface Named {} diff --git a/test/files/pos/t9393/NamedImpl.java b/test/files/pos/t9393/NamedImpl.java deleted file mode 100644 index 7918739c2b..0000000000 --- a/test/files/pos/t9393/NamedImpl.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (C) 2009-2015 Typesafe Inc. - */ -package bug; - -import bug.Named; -import java.io.Serializable; -import java.lang.annotation.Annotation; - -public class NamedImpl implements Named { - - public Class annotationType() { - return null; - } -} diff --git a/test/files/pos/t9393/NamedImpl_1.java b/test/files/pos/t9393/NamedImpl_1.java new file mode 100644 index 0000000000..02ec9b4671 --- /dev/null +++ b/test/files/pos/t9393/NamedImpl_1.java @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2009-2015 Typesafe Inc. + */ +package bug; + +import bug.Named_1; +import java.io.Serializable; +import java.lang.annotation.Annotation; + +public class NamedImpl_1 implements Named_1 { + + public Class annotationType() { + return null; + } +} diff --git a/test/files/pos/t9393/NamedImpl_2.java b/test/files/pos/t9393/NamedImpl_2.java new file mode 100644 index 0000000000..c87e94016d --- /dev/null +++ b/test/files/pos/t9393/NamedImpl_2.java @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2009-2015 Typesafe Inc. + */ +package bug; + +import bug.Named_2; +import java.io.Serializable; +import java.lang.annotation.Annotation; + +public class NamedImpl_2 implements Named_2 { + + public Class annotationType() { + return null; + } +} diff --git a/test/files/pos/t9393/Named_1.java b/test/files/pos/t9393/Named_1.java new file mode 100644 index 0000000000..30a6c9839a --- /dev/null +++ b/test/files/pos/t9393/Named_1.java @@ -0,0 +1,3 @@ +package bug; + +public @interface Named_1 {} diff --git a/test/files/pos/t9393/Named_2.java b/test/files/pos/t9393/Named_2.java new file mode 100644 index 0000000000..3210fb636a --- /dev/null +++ b/test/files/pos/t9393/Named_2.java @@ -0,0 +1,3 @@ +package bug; + +public @interface Named_2 {} diff --git a/test/files/pos/t9393/test.scala b/test/files/pos/t9393/test.scala deleted file mode 100644 index 4df0476c98..0000000000 --- a/test/files/pos/t9393/test.scala +++ /dev/null @@ -1,3 +0,0 @@ -class C { - new bug.NamedImpl -} diff --git a/test/files/pos/t9393/test_2.scala b/test/files/pos/t9393/test_2.scala new file mode 100644 index 0000000000..8ea346129d --- /dev/null +++ b/test/files/pos/t9393/test_2.scala @@ -0,0 +1,4 @@ +class C { + new bug.NamedImpl_1 // separate compilation, testing the classfile parser + new bug.NamedImpl_2 // mixed compilation, testing the java source parser +} -- cgit v1.2.3