Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365079 - [Xtend] create-method's cache doesn't honor type parameters
Summary: [Xtend] create-method's cache doesn't honor type parameters
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: M4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-29 10:52 EST by Moritz Eysholdt CLA
Modified: 2017-09-19 17:07 EDT (History)
1 user (show)

See Also:
sven.efftinge: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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