Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365079

Summary: [Xtend] create-method's cache doesn't honor type parameters
Product: [Modeling] TMF Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sven.efftinge
Version: unspecifiedFlags: sven.efftinge: juno+
Target Milestone: M4   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description Moritz Eysholdt CLA 2011-11-29 10:52:11 EST
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);"
Comment 1 Sven Efftinge CLA 2011-12-01 12:52:59 EST
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.
Comment 2 Karsten Thoms CLA 2017-09-19 16:56:11 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 3 Karsten Thoms CLA 2017-09-19 17:07:07 EDT
Closing all bugs that were set to RESOLVED before Neon.0