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

Bug 362237

Summary: [xtend] illegal Java code generated for closure call
Product: [Tools] Xtend Reporter: Knut Wannheden <knut.wannheden>
Component: CoreAssignee: Project Inbox <xtend-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dennis.huebner, sebastian.zarnekow
Version: 2.2.0Flags: sven.efftinge: kepler+
Target Milestone: M6   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on: 376037    
Bug Blocks:    

Description Knut Wannheden CLA 2011-10-27 15:53:21 EDT
For the following Xtend2 class:

class Other<T> {
	def bar((T)=>Object o) {
		o.apply(42) // <- obviously wrong
	}
}

the following illegal Java is generated:

import org.eclipse.xtext.xbase.lib.Functions.Function1;

@SuppressWarnings("all")
public class Other<T extends Object>  {
  public Object bar(final Function1<? super T,? extends Object> o) {
    Object _apply = o.apply(((Integer)42));
    return _apply;
  }
}


There is no corresponding Xtend2 marker.
Comment 1 Knut Wannheden CLA 2012-10-12 02:34:03 EDT
Interestingly enough Xtend properly reports an error marker by moving the generic type parameter to the method level:

class Other {
	def <T> bar((T)=>Object o) {
		o.apply(new Integer(42)) // <- obviously wrong
	}
}

The error is then: "Incompatible types. Expected T but was java.lang.Integer".
Comment 2 Dennis Huebner CLA 2013-02-13 06:11:53 EST
Fixed in the meantime
Comment 3 Eclipse Webmaster CLA 2017-10-31 11:06:50 EDT
Requested via bug 522520.

-M.
Comment 4 Eclipse Webmaster CLA 2017-10-31 11:18:15 EDT
Requested via bug 522520.

-M.