You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Alain Stalder <as...@span.ch> on 2017/03/05 13:16:04 UTC

Groovy 2.5 SNAPSHOT and final local variables

Not sure if this is the right/best place to report this, but I got this 
with the current head of the master branch of 
https://github.com/apache/groovy.git (ec3179a455):

--
final File file = new File('whatever')
final List<String> lines
try {
   lines = file.readLines()
} catch (IOException e) {
   return null
}
--

=>

1 compilation error:

The variable [lines] may be uninitialized
. At [2:20]  at line: 2, column: 20

--
final File file = new File('whatever')
final List<String> lines
try {
   lines = file.readLines()
} catch (IOException e) {
   lines = null
}
--

=>

1 compilation error:

The variable [lines] is declared final but is reassigned
. At [6:3]  at line: 6, column: 3



Re: Groovy 2.5 SNAPSHOT and final local variables

Posted by Cédric Champeau <ce...@gmail.com>.
This is an interesting topic. I had started implementing this, but never
managed to finish, because of higher priorities (migration to ASF, Codehaus
shutdown). It means the implementation of effectively final variables
inference is not ready, and buggy. I doubt I will have time to fix, which
probably means disabling in 2.5, unless someone else takes it over.

2017-03-05 21:45 GMT+01:00 Paul King <pa...@asert.com.au>:

> I noticed a few similar problems recently (GROOVY-8093, GROOVY-8094)
> but yours looks slightly different again. Probably worth creating an
> issue.
>
> On Sun, Mar 5, 2017 at 11:16 PM, Alain Stalder <as...@span.ch> wrote:
> > Not sure if this is the right/best place to report this, but I got this
> with
> > the current head of the master branch of
> > https://github.com/apache/groovy.git (ec3179a455):
> >
> > --
> > final File file = new File('whatever')
> > final List<String> lines
> > try {
> >   lines = file.readLines()
> > } catch (IOException e) {
> >   return null
> > }
> > --
> >
> > =>
> >
> > 1 compilation error:
> >
> > The variable [lines] may be uninitialized
> > . At [2:20]  at line: 2, column: 20
> >
> > --
> > final File file = new File('whatever')
> > final List<String> lines
> > try {
> >   lines = file.readLines()
> > } catch (IOException e) {
> >   lines = null
> > }
> > --
> >
> > =>
> >
> > 1 compilation error:
> >
> > The variable [lines] is declared final but is reassigned
> > . At [6:3]  at line: 6, column: 3
> >
> >
>

Re: Groovy 2.5 SNAPSHOT and final local variables

Posted by Paul King <pa...@asert.com.au>.
I noticed a few similar problems recently (GROOVY-8093, GROOVY-8094)
but yours looks slightly different again. Probably worth creating an
issue.

On Sun, Mar 5, 2017 at 11:16 PM, Alain Stalder <as...@span.ch> wrote:
> Not sure if this is the right/best place to report this, but I got this with
> the current head of the master branch of
> https://github.com/apache/groovy.git (ec3179a455):
>
> --
> final File file = new File('whatever')
> final List<String> lines
> try {
>   lines = file.readLines()
> } catch (IOException e) {
>   return null
> }
> --
>
> =>
>
> 1 compilation error:
>
> The variable [lines] may be uninitialized
> . At [2:20]  at line: 2, column: 20
>
> --
> final File file = new File('whatever')
> final List<String> lines
> try {
>   lines = file.readLines()
> } catch (IOException e) {
>   lines = null
> }
> --
>
> =>
>
> 1 compilation error:
>
> The variable [lines] is declared final but is reassigned
> . At [6:3]  at line: 6, column: 3
>
>