eclipse-xtext / eclipse-xtext/xtext
Compiler picks wrong `it` to access an external property inside an anonymous class when mapping a list
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 831
- Forks
- 330
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 12
Description
class Test {
static class Thing {
var Object property
}
def test(List<Object> objects) {
objects.map [
new Thing => [
property = new Object() {
val oldValue = property // Java error
}
]
]
}
}
The 2.28.0.v20220829-0536 compiler produced invalid Java for this by selecting the wrong it for the access to property inside the anonymous object.
It is worth mentioning that the issue is only present when objects is a List and the transformation is a map, so somehow the logic breaks due to some difference between the implementations of map in IterableExtensions and ListExtensions.
The issue can be avoided by explicitly defining the lambda variable it for the arrow operator's lambda: => [it|...]
There is no linking error in either case.
May be related to eclipse/xtext-xtend#1301.
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 supplied Test reproducer and inspect how the compiler resolves it for the nested lambdas. Compare the map paths in IterableExtensions and ListExtensions, which the issue identifies as differing. Done means the List/map case selects the external property correctly and produces valid Java without requiring an explicit lambda variable.
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
- 42/100