-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Port Constant Types for Literal Final Static Java Fields and Implicit Conversions from Scalac #7483
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
Conversation
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
Not sure I understand, what error are you seeing with that test exactly ? |
@smarter Here is the code which triggers the same error:
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface J {
String value();
}
object C {
val cs: String = "cs"
}
object S {
@J(C.cs)
def f(): Int = 1
}
|
That code emits a "annotation argument is not a constant" in scalac, I've just created a PR to do the same for dotty: #7495 |
@smarter Thanks for the crash fix! However, with this fix, the annotation arguments still cannot be constants. That's why I am not able to port the test of SI-3236. |
OK, I've pushed an extra commit to #7495 which handles this. |
If you rebase on master you should be able to add these tests now. |
@smarter Thanks, the SI-3236 test is now added. |
Currently, the
ClassParser
will giveConstantType
s to constant fields, but theJavaParser
will not, because theJavaParser
in Dotty doesn’t parse the expressions of fields. This PR ports the parsing literals part from Scalac, so thatConstantType
s will be assigned to constant Java fields with simple literals.SI-3236 constant types for literal final static java fields
scala/scala@81d2c61
Support implicit converstions from java literals
scala/scala@74c613b
This is also useful for the explicit nulls #6344. With this feature, we don’t need to nullify constant fields.
I am not able to port the test of SI-3236 directly, since the annotation arguments in Dotty can only refers to enum values (in
DottyBackendInterface.emitArgument
)? If I’m wrong, please correct me.Edit: The SI-3236 test is now ported.