eclipse-xtext / eclipse-xtext/xtext
Invalid generation of variable declarations against lambda declaration
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
Let the DSL code:
import java.util.UUID
class MyClass {
def void fct2((UUID) => boolean lambda) {
}
def void fct() {
var UUID id
id = UUID.randomUUID
fct2 [it == id]
}
}
The generated Java code causes the error: Java problem: Local variable id defined in an enclosing scope must be final or effectively final.
The expected behavior is: no error.
The generated Java code for the fct function is:
UUID id = null;
id = UUID.randomUUID();
final Function1<UUID, Boolean> _function = (UUID it) -> {
return Boolean.valueOf(Objects.equal(it, id));
};
this.fct2(_function);
The expected Java code is:
UUID id;
id = UUID.randomUUID();
final Function1<UUID, Boolean> _function = (UUID it) -> {
return Boolean.valueOf(Objects.equal(it, id));
};
this.fct2(_function);
The initialization to null of the local variable id is invalid within the Java code.
And, it is not expected because it is not specified into the DSL code.
Possible solution: avoid the XbaseCompiler to generate initialization to the default value when declaring a local variable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the XbaseCompiler mentioned in the issue and reproduce the DSL example using the shown lambda and local variable declaration. Compare the generated Java with the expected output, then verify that the generated code compiles without the effectively-final error and does not initialize id to null.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100