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

Bug 346763

Summary: IterableExtensions should support Iterable<? extends T>
Product: [Modeling] TMF Reporter: Benjamin Schwertfeger <benjamin.schwertfeger>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: mail, sebastian.zarnekow
Version: 2.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: SR2   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Benjamin Schwertfeger CLA 2011-05-20 16:15:13 EDT
Build Identifier: I20110310-1119   Xtend2 SDK: 2.0.0.v201105191503

The IterableExtensions contains many methods for Iterable-Operations. If in the .xtend-File a Set<? extends Extension> is defined, it is translated to IterableExtensions.<Extension>forEach(...). This leads to Iterable<Extension> as first required parameter, but it is a <? extends Extension>.

The methods in IterablesExtension should be defined like
  public static final <T> void forEach(Iterable<? extends T> iterable, Function1<? super T, ?> function) {



Reproducible: Always

Steps to Reproduce:
1. Add this code to one xtend-File:
> var List<? extends String> v = null;
> v.forEach(e|e.toString())
2. Save and let it be compiled
3. The generated Java-File contains an error
Comment 1 Sebastian Zarnekow CLA 2011-05-20 16:19:31 EDT
This is a bug in the compiler / validation and not in the iterable extensions.
Comment 2 Sebastian Zarnekow CLA 2011-05-20 16:26:53 EDT
The generated code should look like this if the parameters' type is something with a wildcard extends:

List<? extends String> list = null;
IterableExtensions.forEach(list, new Functions.Function1<Object, String>() {
	public String apply(Object p) {
		return null;
	}
});
Comment 3 Benjamin Schwertfeger CLA 2011-05-20 16:53:43 EDT
The same problem exists for the ListExtensions.map function. Here the function must be of the correct type to call methods on the elements.

var List<MyDslGenerator> v = new ArrayList<MyDslGenerator>();
  v.add(new MyDslGenerator());
  var List<? extends IGenerator> v2 = v;
  var m2 = v2.map(e|e.toString())
Comment 4 Sebastian Zarnekow CLA 2011-08-28 12:48:16 EDT
The issues are sill reproducable
Comment 5 Sebastian Zarnekow CLA 2011-09-29 09:43:17 EDT
Pushed to master.
Comment 6 Karsten Thoms CLA 2017-09-19 18:01:24 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 18:11:45 EDT
Closing all bugs that were set to RESOLVED before Neon.0