Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343144 - [Xtend2] glitch in autoboxing/type inference?
Summary: [Xtend2] glitch in autoboxing/type inference?
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-18 08:33 EDT by Moritz Eysholdt CLA
Modified: 2017-09-19 17:08 EDT (History)
1 user (show)

See Also:
sebastian.zarnekow: indigo+


Attachments

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