| Summary: | Incorrect code generated when using the '?.' operator in the context of a closure or for loop | ||
|---|---|---|---|
| Product: | [Tools] Xtend | Reporter: | Lieven Lemiengre <lieven.lemiengre> |
| Component: | Core | Assignee: | Project Inbox <xtend-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | major | ||
| Priority: | P3 | CC: | sebastian.zarnekow, sven.efftinge |
| Version: | 2.2.0 | Flags: | sven.efftinge:
juno+
|
| Target Milestone: | M6 | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
Already fixed in M6 Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
package xtend.bugs import java.util.List class Bugs { def bug(List<Object> xs) { for(x : xs) { x?.foo } xs.forEach [ it?.foo ] } def void foo(Object o) { } } The generated java code is wrong: package xtend.bugs; import java.util.List; import org.eclipse.xtext.xbase.lib.IterableExtensions; import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; @SuppressWarnings("all") public class Bugs { public void bug(final List<Object> xs) { for (final Object x : xs) { x==null?(void)null:this.foo(x); } final Procedure1<Object> _function = new Procedure1<Object>() { public void apply(final Object it) { it==null?(void)null:Bugs.this.foo(it); } }; IterableExtensions.<Object>forEach(xs, _function); } public void foo(final Object o) { } } 2 problems: - casting to 'void' is impossible - in this case the ternary operator can't be used, it should be replaced with an if statement