| Summary: | [Xtend2] glitch in autoboxing/type inference? | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Moritz Eysholdt <moritz.eysholdt> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sebastian.zarnekow |
| Version: | unspecified | Flags: | sebastian.zarnekow:
indigo+
|
| Target Milestone: | M7 | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
It's a bug. Pushed to master. Closing all bugs that were set to RESOLVED before Neon.0 Closing all bugs that were set to RESOLVED before Neon.0 |
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.