-
Notifications
You must be signed in to change notification settings - Fork 320
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
XtendJvmModelInferrer and treatment of anonymous classes #2886
Comments
Even though a class is an anonymous class in Xtend, it’s not necessary possible to compile it to an anonymous Java class. In some cases , it’s necessary to compile to a named, local class. |
@szarnekow but if I understand correctly, that's only a code generation strategy; I mean, that check could be delayed to code generation instead of at the JVM inferer level. I did a quick experiment (setting isAnonymous to true) and the failing test only concern code generation. Can it be? |
I might be confused. The JVM model is the input model for the code generator, no? |
@szarnekow but from a JVM model's point of view, Xtend anonymous classes could always be mapped to anonymous JvmGenericTypes; it's just that, as you said, in some cases, the Java code generation must be different. I was proposing to do the check when generating code, not when inferring the JVM model. This would allow me to always detect JVM anonymous classes (in #2880), while not changing the Xtend compilation. I'm doing some experiments in that direction. |
I don‘t think it’s true. To make the additionally defined members accessible in Java from the enclosing method, you need a named type in Java8. It‘s not a given that these members are ever accessed, but we don’t know that during model inference. I’m curious about your findings though. |
@szarnekow here's my experiment (build is green) the changes are rather minimal:
All the tests are still green (https://github.com/LorenzoBettini/xtext/actions/runs/7365585524): in particular, the compiled code is the same as before. I'm not sure I understand the case you mentioned above. class Foo {
def m() {
val e = new Exception("") {
int i = 0;
}
e.i = 3
}
} This behaves as before: type inference and validation work as before, and the Java code is generated as before, that is, with a local class in the generated Java method. From what I understand, as long as the inferrer does |
@szarnekow I have another working proposal for this issue that does not touch the inferred model. I created a PR on my fork LorenzoBettini#1 because the proposal is built on top of #2890; the changes are rather minimal:
This way, during the Xtend compilation process, anonymous classes are correctly generated as Java anonymous classes or nested local classes. All the tests are green. All the generated code is as before. No test has been touched apart from this one https://github.com/LorenzoBettini/xtext/pull/1/files#diff-8d2c98464642a8554f494c6f4c1de6f865cbec0d6cb5b288412da41e6067cba1L222 of course. If #2890 gets merged, and you think that LorenzoBettini#1 makes sense I'll create a PR for this repository. |
@szarnekow disregard the previous comment, which is now stale. I've created the new #2898, where I updated the comments. |
Fixed by #2898 |
The Xtend inferrer does this:
Thus, an anonymous Xtend class is NOT mapped to a
JvmGeneritcType.isAnonymous
if it contains a field or a non-overridden method.Is there a specific reason?
While working on #2880 I'd like to analyze also JvmGenericTypes corresponding to anonymous classes, but with the above behavior, I cannot correctly detect them: if
isAnonymous
returnsfalse
it can still correspond to an anonymous class. Some checks on anonymous classes must be different from standard classes or interfaces. First, an anonymous class's supertype can be a class or interface. For standard classes, I have to distinguish between the intended superclass and the intended implemented interfaces.cc @szarnekow
The text was updated successfully, but these errors were encountered: