Skip to content

SI-3236 constant types for literal final static java fields #5487

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

Merged
merged 3 commits into from
Dec 15, 2016

Conversation

lrytz
Copy link
Member

@lrytz lrytz commented Oct 28, 2016

No description provided.

@scala-jenkins scala-jenkins added this to the 2.11.9 milestone Oct 28, 2016
@lrytz lrytz force-pushed the java-constants branch 3 times, most recently from 97c5cc0 to 6a90bd3 Compare October 28, 2016 14:56
Since we don't parse Java expressions, fields of Java classes coming
from source files never have constant types. This prevents using
static java fields in annotation arguments in mixed compilation

This PR assigns constant types to final static java fields if the
initializer is a simple literal.
@lrytz
Copy link
Member Author

lrytz commented Oct 28, 2016

As mentioned in the original PR, this could be expanded to support (some) composite expressions, but it would be a bigger effort. For that, instead of trying to constant fold and assign types in the parser, I think we should just parse the expression and pass it on to the Scala type checker. But that's also not easy by any means :)

@lrytz
Copy link
Member Author

lrytz commented Oct 28, 2016

I think the code here is an OK compromise, even with its limitations. For example, it treats !1 as -1. But the Java compiler would reject that of course.

@lrytz
Copy link
Member Author

lrytz commented Oct 28, 2016

@jrudolph please take a look.

@jrudolph
Copy link
Contributor

On first glance, I think it looks good 👍

Would it make sense to add tests for the additional feature of implicitly converting the constants?

@lrytz
Copy link
Member Author

lrytz commented Oct 28, 2016

yes, also some neg tests to make sure the limits are checked. will do.

@adriaanm
Copy link
Contributor

One last test failure: test/files/run/t3236 doesn't compile.

For example, public static final byte b = 127 is allowed, but 128 is
not.

Also factor out a method that parses a literal. It could be used to
parse annotations (and their literal arguments) in Java sources.
@lrytz
Copy link
Member Author

lrytz commented Nov 2, 2016

Added a neg test to frame the limitations

@lrytz
Copy link
Member Author

lrytz commented Nov 3, 2016

review by @adriaanm

@jrudolph
Copy link
Contributor

jrudolph commented Nov 3, 2016

👍 new tests LGTM

@lrytz lrytz requested a review from adriaanm December 14, 2016 12:11
Copy link
Contributor

@adriaanm adriaanm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adriaanm
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants