| Summary: | name collision w.r.t. '_class' and closures in Xtend2 | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Meinte Boersma <meinte.boersma> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sebastian.zarnekow, sven.efftinge |
| Version: | unspecified | Flags: | sebastian.zarnekow:
juno+
|
| Target Milestone: | M4 | ||
| Hardware: | Macintosh | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
_xyz is the reserved namespace for the synthetic variables that the compiler creates. We need a validation that user variables don't start with an underscore. Alternatively, you could scan for things prefixed with _ and rig the mechanism for giving internal synthetic variables a unique name with that. The validation is much simpeler, but especially people coming from JS coding have a tendency to use the _ prefix. Also, the 'class' name is a bit cumbersome in itself. pushed to master We should check whether a given name is used by a user variable, such that we end up with as little numbered variable names as possible. pushed to master should have been "pushed to 2.1.x_Maintenance" :-) Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
Build Identifier: 20110615-0604 Use of Java's Object#getClass() method leads to creation of statement "Class<? extends Object> _class = item.getClass();" after compilation to Java. This may shadow a pre-existing method parameter without chance of accessing the original one in the Xtend code when using closures, which is hard to debug. As an example: def <T> Iterable<T> asIterable(JSONArray jsonArray, Class<T> _class) { jsonArray.asIterableInternal( [ item, list | if( _class.isAssignableFrom(item.^class) ) { list.add(_class.cast(item)) } else { throw new IllegalArgumentException('''item is of type «item.^class.name» and cannot be cast to «_class.name»'''.toString) } ] ) } And the dependency: def <T> Iterable<T> asIterableInternal(JSONArray jsonArray, org.eclipse.xtext.xbase.lib.Functions$Function2<Object, List<T>, ?> action) { val len = jsonArray.length val iterable = new ArrayList<T>(len) var i = 0 while( i < len ) { try { val item = jsonArray.get(i) action.apply(item, iterable) } catch( Exception e ) { throw new RuntimeException('''cannot obtain item with index «i» from JSONArray'''.toString, e) } i = i+1 } iterable } (Renaming the parameter '_class' to e.g. 'clazz' resolves the problem.) Reproducible: Always Steps to Reproduce: 1. see details 2. 3.