| Summary: | [xtend] Uncompilable code when using loop variable in a function | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Karsten Thoms <karsten.thoms> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sebastian.zarnekow |
| Version: | 2.0.0 | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | SR1 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
This one was already fixed for SR1 Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
This Xtend code produces uncompilable code: ============================================= for (e : model.entities) { val p = model.configuration.classes.findFirst(c|c.entityName==e.name) e.persistentClass = p } ============================================= "e" is in this case not final, but used within a function: "Cannot refer to a non-final variable e inside an inner class defined in a different method" ============================================= for (Entity e : _entities) { { Configuration _configuration = this.model.getConfiguration(); EList<PersistentClass> _classes = _configuration.getClasses(); final Function1<PersistentClass,Boolean> _function = new Function1<PersistentClass,Boolean>() { public Boolean apply(final PersistentClass c) { String _entityName = c.getEntityName(); String _name = e.getName(); <== *** ERROR boolean _operator_equals = ObjectExtensions.operator_equals(_entityName, _name); return ((Boolean)_operator_equals); } }; PersistentClass _findFirst = IterableExtensions.<PersistentClass>findFirst(_classes, _function); final PersistentClass p = _findFirst; e.setPersistentClass(p); } } ============================================= Workaround: Create a val for the loop variable: ============================================= for (e : model.entities) { val e1 = e val p = model.configuration.classes.findFirst(c|c.entityName==e1.name) e1.persistentClass = p } ============================================= Maybe the loop's variable should be compiled as final?