RFR 8200199: javac suggests to use var even when var is used

Jan Lahoda jan.lahoda at oracle.com
Wed Mar 28 10:56:13 UTC 2018

Looks good to me.


On 28.3.2018 12:52, Maurizio Cimadamore wrote:
> Hi,
> there is an issue with the local variable inference finder: the finder
> reports possible cases where 'var' could be used even when the developer
> has already used 'var'. This is due to a timing issue with which the
> analyzer runs - by the time it runs, variable types have already been
> written into the AST by Attr - so the call to
> JCVarDecl.isImplicitlyTyped() is moot, as that call will simply look to
> see as to whether the tree type == null.
> Since the var types corresponding to implicitly inferred types are
> synthetic and have no position set (see Attr::setSyntheticVariableType)
> I decided to use that property instead to decide as to whether the
> analyzer should, or should not consider a given variable declaration.
> This seems to be a good pragmatic solution. In the long run we should
> probably consolidate the treatment of implicitly inferred variables, and
> have some kind of common way to speak about them (e.g. both locals and
> implicit lambda parameters).
> Webrev:
> http://cr.openjdk.java.net/~mcimadamore/8200199/
> Cheers
> Maurizio

More information about the compiler-dev mailing list