Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362285 - [xbase][types] problem with type inference of closure return type
Summary: [xbase][types] problem with type inference of closure return type
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: M6   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-28 05:06 EDT by Knut Wannheden CLA
Modified: 2013-02-16 09:04 EST (History)
0 users

See Also:
knut.wannheden: kepler+


Attachments

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