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

Bug 343144

Summary: [Xtend2] glitch in autoboxing/type inference?
Product: [Modeling] TMF Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: unspecifiedFlags: sebastian.zarnekow: indigo+
Target Milestone: M7   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Moritz Eysholdt CLA 2011-04-18 08:33:03 EDT
This works:
----
newArrayList("ab", "abc").fold(0 as Integer, [s,  max | Math::max(s.length, max)])
----

This works, too:
----
newArrayList("ab", "abc").fold(0, [s, Integer max | Math::max(s.length, max)])
----

This does *not* work:
----
newArrayList("ab", "abc").fold(0, [s,  max | Math::max(s.length, max)])
----

The error message is:
----
Incompatible types. Expected org.eclipse.xtext.xbase.lib.Functions$Function2<java.lang.String,java.lang.Integer,? extends java.lang.Integer> but was org.eclipse.xtext.xbase.lib.Functions$Function2<java.lang.String,? extends java.lang.Object & super int,java.lang.Integer>
----

The problem is that in the third scenario I didn't specify the type for closures' second/third parameter explicitly. The type for the second and third parameter is expected to be the same.

In the third example type is derived to be "int" (from fold()'s first parameter: "0") which is represented as "? extends java.lang.Object & super int" which seems to be incompatible with "? extends java.lang.Integer".

Not sure if this is actually a bug or whether I've reached the boundaries of type inference.
Comment 1 Sebastian Zarnekow CLA 2011-04-18 08:36:19 EDT
It's a bug.
Comment 2 Sebastian Zarnekow CLA 2011-04-19 17:15:58 EDT
Pushed to master.
Comment 3 Karsten Thoms CLA 2017-09-19 16:56:52 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 4 Karsten Thoms CLA 2017-09-19 17:08:05 EDT
Closing all bugs that were set to RESOLVED before Neon.0