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

Bug 351330

Summary: [xtend] Xtend compiler generates invalid java code
Product: [Modeling] TMF Reporter: Bernd Kolb <b.kolb>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P3 CC: sebastian.zarnekow
Version: unspecifiedFlags: sebastian.zarnekow: indigo+
Target Milestone: SR1   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Bernd Kolb CLA 2011-07-06 09:45:44 EDT
Build Identifier: 3.7.0 final Eclipse release, xtext distro from itemis

The xtend2 compiler generates invalid java code for the following function:

def toSeparatedString(Iterable<T> i, (T)=>String toStringFunc, String separator){
	i.map(T x | toStringFunc.apply(x)).join(separator)
}


The result looks as follows:

public String toSeparatedString(final Iterable<?> i, final Function1<?,String> toStringFun, final String separator) {
    final Function1<?,String> _function = new Function1<?,String>() {
        public String apply(final ? x) {
          String _apply = toStringFun.apply(x);
          return _apply;
        }
      };
    Iterable<String> _map = IterableExtensions.<?, String>map(i, _function);
    String _join = IterableExtensions.join(_map, separator);
    return _join;
  }


The inner apply Method uses ? as a type

Reproducible: Always
Comment 1 Sebastian Zarnekow CLA 2011-07-06 11:45:33 EDT
This is documented in the disabled testcase  org.eclipse.xtext.xtend2.tests.linking.InferredJvmModelTest.testInferredFunctionWithTypeParameter()
Comment 2 Sebastian Zarnekow CLA 2011-07-13 09:41:37 EDT
The code snippet seems to be invalid: T is nowhere defined. 
Bernd, did you declare T as a type parameter for the Xtend class?
Comment 3 Sebastian Zarnekow CLA 2011-07-13 10:00:50 EDT
Added some test cases to document that the generated code is correct as long as T was defined somewhere. Since there are error markers if T was not defined, I close this ticket. Please reopen and provide a complete Xtend file if the problem is still present in the latest nightlies.
Comment 4 Karsten Thoms CLA 2017-09-19 16:55:24 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:06:09 EDT
Closing all bugs that were set to RESOLVED before Neon.0