| Summary: | [Xtend] create-method's cache doesn't honor type parameters | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Moritz Eysholdt <moritz.eysholdt> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sven.efftinge |
| Version: | unspecified | Flags: | sven.efftinge:
juno+
|
| Target Milestone: | M4 | ||
| Hardware: | Macintosh | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
This cannot be fixed easily, since we would have to resolve the return type, which is derived eagerly. I added a validation, preventing people to use generified create methods. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
Example: ------- class foo<T> { def <X> create new foo<X>() newFoo() { } } ------- this compiles to the following erroneous Java code -------- public class foo<T extends Object> { public <X extends Object> foo<X> newFoo() { final ArrayList<?>_cacheKey = CollectionLiterals.newArrayList(); final foo<?> _result; synchronized (_createCache_newFoo) { if (_createCache_newFoo.containsKey(_cacheKey)) { return _createCache_newFoo.get(_cacheKey); } foo<X> _foo = new foo<X>(); _result = _foo; _createCache_newFoo.put(_cacheKey, _result); } _init_newFoo(_result); return _result; } private final HashMap<ArrayList<?>,foo<?>> _createCache_newFoo = CollectionLiterals.newHashMap(); private void _init_newFoo(final foo<?> it) { } } ----------- It's not compilable, because - "final foo<?> _result;" needs to be "foo<X>"; - "return _createCache_newFoo.get(_cacheKey);" needs a cast: "return (foo<X>) _createCache_newFoo.get(_cacheKey);"