New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse annotation in jointly compiled Java source files and honour @Deprecated #8781
Parse annotation in jointly compiled Java source files and honour @Deprecated #8781
Conversation
ed48b8e
to
2fbee71
Compare
This comment has been minimized.
This comment has been minimized.
src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for (hopefully) getting this over the finish line. Third time's the charm.
df76334
to
cc25950
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Suggestions by @retronym how we could handle annotation arguments that scalac fails to interpret:
@hrhino reminded us that on JDK 11+, Java's |
cc25950
to
5ef207b
Compare
I implemented this solution, using |
The change to drop annotations looks good. Maybe add add a test that shows annotations are dropped in mixed compilation? I also think an opt-in warning would be good. Also, I was confused how references to Java compile-time constants work - now I remember, they are handled by the Java parser, which assigns a constant type to such fields where possible: #5487. So unfortunately that means we need a way to silently drop annotatnions during type checking, for the case when the argument is not a compile-time constant: public class C {
public static @interface Ann {
String value();
}
@Ann("a") public static int x0 = 0; // ok
@Ann("a" + "b") public static int x1 = 1; // ok, dropped
@Ann(C.konst) public static int x2 = 2; // ok
@Ann(C.nokst) public static int x3 = 3; // error when type-checking
public static final String konst = "muk";
public static final String nokst = "muk" + "y";
} with
and later
|
This causes the java parser to get somewhat more complex, but allows for macros and compiler plugins to correctly inspect java-defined classes for annotations. Moved a few utility methods into {Parsers,Scanners}Common as well, so I can reuse them in the java ones. This involves a change to the t4788 tests, as SAnnotation now correctly has RetentionPolicy.SOURCE, and is therefore ignored by the check in BCodeHelpers#BCAnnotGen.shouldEmitAnnotation; also, ASM Textifier emits an // invisible marker now that CAnnotation has RetentionPolicy.CLASS. I'm not sure what the chances that anyone is relying upon this behavior are, but since it does the Right Thing for separate compilation runs, they probably should not be too disappointed. The new tests are run-tests not just pos-tests at the suggestion of retronym, to ensure that everything works the same at runtime as it does at compile time. As a matter of fact, it doesn't: the compile-time universe maintains ordering of annotation values in the tree, while the runtime universe uses java reflection to get at the values and therefore cannot know of their order. The test contains one exception for that. Review by densh, retronym Fixes scala/bug#8928 Co-authored-by: Jason Zaugg <jzaugg@gmail.com> Co-authored-by: Dale Wijnand <dale.wijnand@gmail.com>
5ef207b
to
3c89087
Compare
😕 That proved harder to do than expected (to me) using partest's existing machinery. The reason is it's not possible to have java sources that
Any suggestions? Lukas suggests @retronym or @hrhino might have a good suggestion, but also that there's no need to spend too much time on it.
Suggestions (on both) welcome. 😄
Done! ✅ |
how about an |
Discussed in the team today: decided not to add it for now (misc reasons: very niche, mostly So this is GTG now. |
Missed opportunity for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This triggered a spurious kind error with |
One more: #8982 |
* A port of fixes from scala/scala#8781 with improvements. * Some of improvements come from scala/scala#8982. * There are small changes to typer to allow for single elements of any type T be used where array of T is expected inside of java annotations arguments as it is correct in java and is used in 2 files in scala standard library.
Rebased (with a small merge conflict) @hrhino's work in #5892 & extended it to handle
@Deprecated
.Fixes scala/bug#8928 ("Java parser skips over annotations"), though limited to no args annotations and annotations with literal arguments.
Fixes scala/bug#9617 ("Deprecations from Java may be not taken into account in mixed projects") which is the joint-compilation variant of scala/bug#10752 (which was just fixed).
Fixes scala/bug#8883 ("Treat java / scala deprecated annotations more uniformly") (IMO) with the deprecated attribute adding the java annotation &
Symbol#isDeprecated
considering both.