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

Bug 362285

Summary: [xbase][types] problem with type inference of closure return type
Product: [Modeling] TMF Reporter: Knut Wannheden <knut.wannheden>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 Flags: knut.wannheden: kepler+
Version: 2.1.0   
Target Milestone: M6   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Knut Wannheden CLA 2011-10-28 05:06:21 EDT
For the following Xtend2 file:

public class Foo<T> {
	def foo() {
		[T x|x].apply(null)
	}	
}

an error marker is generated for the closure body expression "x": "Incompatible implicit return type. Expected T but was Result". I don't think there should be an error marker in this case.

Workarounds. Change the code to read:

public class Foo<T> {
	def foo() {
		[T x|x as T].apply(null)
	}	
}

or:

public class Foo<T> {
	def T foo() {
		[T x|x].apply(null)
	}	
}
Comment 1 Knut Wannheden CLA 2011-10-28 05:08:20 EDT
I was further surprised to find that the example works if the generic type is declared on the method instead:

public class Foo {
	def <T> foo() {
		[T x|x].apply(null)
	}
}
Comment 2 Knut Wannheden CLA 2013-02-16 09:04:15 EST
This bug has been fixed in Xtend 2.4.