Bug 440529 - Loss of type information when calling <Map.Entry-array>.get(x)
Summary: Loss of type information when calling <Map.Entry-array>.get(x)
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.6.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2014-07-28 06:26 EDT by Sebastien Diot CLA
Modified: 2017-09-07 11:58 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastien Diot CLA 2014-07-28 06:26:57 EDT
The following small test program gives me unexpected results when compiling:

    package test

    import java.util.HashMap
    import java.util.Map
    import org.junit.Test

    import static org.junit.Assert.*

    class MapTest {
        @Test
        public def void testCreation() {
            val map = new HashMap<String,Long>()
            val one = "one"
            map.put(one, 1L)
            val esa = map.entrySet.toArray(<Map.Entry>newArrayOfSize(1))
            assertNotNull("map.entrySet.toArray", esa)
            assertEquals("map.entrySet.toArray.length", 1, esa.length)
            // esa0 is an Object, but should be a Map.Entry!
            val esa0 = esa.get(0)
            assertNotNull("map.entrySet.toArray[0]", esa0)
    //        assertEquals("map.entrySet.toArray[0].key", one, esa0.key)
    //        assertEquals("map.entrySet.toArray[0].value", 1L, esa0.value)
        }
    }


The problem is esa; is should be typed as a Map.Entry, but isn't. And because of that, the last two lines of the test method do not compile.
The line "val esa0 = esa.get(0)" is compiled to:

    final Object esa0 = ((List<Map.Entry>)Conversions.doWrapArray(esa)).get(0);


I am also surprised that <array>.get(x) *wraps the array in a List*. Until now, I was assuming get(int) and set(int) were simply mapped to array[int]; this could result in highly inefficient code...
Comment 1 Sven Efftinge CLA 2014-09-09 03:50:59 EDT
It works when using <Map.Entry<?,?>>newArrayOfSize(1).
Comment 2 Christian Dietrich CLA 2017-09-07 11:58:02 EDT
same with 

val Entry[] esa = #[null]
val esa0 = esa.get(0)
println(esa0)