Should I file a bug report?
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. On 29 September 2015 at 10:17, Dinko Srkoč <dinko.sr...@gmail.com> wrote: > On 29 September 2015 at 10:12, Cédric Champeau > <cedric.champ...@gmail.com> wrote: > > That's because it's withDefault { 1 } ;) > > Argh! Still morning for me. :-( > > > > > 2015-09-29 10:05 GMT+02:00 Dinko Srkoč <dinko.sr...@gmail.com>: > >> > >> On 29 September 2015 at 09:58, Cédric Champeau > >> <cedric.champ...@gmail.com> wrote: > >> > This looks like a bug. Would be interesting to look at the bytecode to > >> > check > >> > what method is called for x[n]. > >> > >> Curiously, I tried to do just that in the Groovy AST Browser and, for > >> the following piece of code: > >> > >> @groovy.transform.CompileStatic > >> def foo() { > >> [].withDefault(1) > >> } > >> > >> got this: > >> > >> Unable to produce AST for this phase due to earlier compilation error: > >> startup failed: > >> script1443513793544.groovy: 3: [Static type checking] - Cannot find > >> matching method java.util.List#withDefault(int). Please check if the > >> declared type is right and if the method exists. > >> @ line 3, column 5. > >> [].withDefault(1) > >> ^ > >> > >> That's Groovy 2.4.4 > >> > >> Cheers, > >> Dinko > >> > >> > > >> > 2015-09-29 9:54 GMT+02:00 Søren Berg Glasius <soe...@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. > >> > > >> > > > > > >