import groovy.transform.CompileStatic
import org.junit.Test
import static groovy.util.GroovyTestCase.assertEquals
class TestGroovyListBug {
@CompileStatic
def swapUseStatic(List<Integer> a, int i, int j) {
int temp = a[i]
a[i] = a[j] a[j] = temp
}
@CompileStatic
def swapUseStaticPut(List<Integer> a, int i, int j) {
int temp = a[i]
a.putAt(i, a[j])
a[j] = temp
}
def swapNonStatic(a, i, j) {
def temp = a[i]
a[i] = a[j]
a[j] = temp
}
@Test
def void testCompileStaticListPut() {
List a = new ArrayList()
a.clear(); a.add(0); a.add(1);
swapNonStatic(a, 0, 1)
assertEquals(1, a[0])
assertEquals(0, a[1])
a.clear(); a.add(0); a.add(1);
swapUseStaticPut(a, 0, 1)
assertEquals(1, a[0])
assertEquals(0, a[1])
a.clear(); a.add(0); a.add(1);
swapUseStatic(a, 0, 1)
assertEquals(1, a[0])
assertEquals(0, a[1])
}
}