groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cédric Champeau <cedric.champ...@gmail.com>
Subject Re: A @CompileStatic bug, or is it just me: [].withDefault { 0 }
Date Tue, 29 Sep 2015 07:58:25 GMT
This looks like a bug. Would be interesting to look at the bytecode to
check what method is called for x[n].

2015-09-29 9:54 GMT+02:00 Søren Berg Glasius <soeren@glasius.dk>:

> Hi Fellows,
>
> I stumbled upon this today.
>
> This code runs:
>
> class Test {
>     private List<Integer> x = [].withDefault { 0 }
>     Integer getValue(int n) {
>         return x[n]
>     }
> }
> assert new Test().getValue(5) == 0
>
> where as when I compile static:
>
> @CompileStatic
> class Test {
>     private List<Integer> x = [].withDefault { 0 }
>     Integer getValue(int n) {
>         return x[n]
>     }
> }
> assert new Test().getValue(5) == 0
>
> I get an assertion failed, because new Test().getValue(5) == null
>
> Is this expected behavior or a bug?
>
>
> Best regards / Med venlig hilsen,
> Søren Berg Glasius
>
> Hedevej 1, Gl. Rye, 8680 Ry, Denmark
> Mobile: +45 40 44 91 88, Skype: sbglasius
> --- Press ESC once to quit - twice to save the changes.
>

Mime
View raw message