JDK 10/11 RFR of JDK-8189146: Have use of "var" in 9 and earlier source versions issue a warning
joe darcy
joe.darcy at oracle.com
Tue Jan 9 18:28:04 UTC 2018
Hello,
When the possibility of "_" being removed from the future set of valid
identifiers was determined, javac was updated to issue a warning to that
effect in JDK 8. Underscore was removed from the set of valid
identifiers as of JDK 9.
With local variable type inference, the name "var" should be given
similar treatment in source versions 9 and earlier. Please review the
webrev which implements this:
http://cr.openjdk.java.net/~darcy/8189146.0/
As written, the patch warns for a type or type variable named "var"; it
would be possible to expand the patch to warn about other uses of "var"
that would conflict with the JDK 10 feature. As a aid to reviewing, the
non-raw diagnostic output from
test/langtools/tools/javac/lvti/ParserTest.java under --release 9 is
listed below.
IMO It would be preferable to issue this kind of warning in the context
of an -Xlint:future category (JDK-8189145), but until that feature is
developed, it is still better to issue the warning than to not issue it.
The webrev as presented is based off of JDK 11. Upon a successful code
review, I will explore getting the change into JDK 10 as an RFE and make
any needed adjustments to rebase the patch. If that is not fruitful,
I'll push the change to JDK 11.
Thanks,
-Joe
ParserTest.java:14: warning: as of release 10, 'var' is a restricted
local variable type and cannot be used for type declarations
class ParserTest<var> {
^
ParserTest.java:16: warning: as of release 10, 'var' is a restricted
local variable type and cannot be used for type declarations
static class var { } //illegal
^
ParserTest.java:20: warning: as of release 10, 'var' is a restricted
local variable type and cannot be used for type declarations
interface var { } //illegal
^
ParserTest.java:24: warning: as of release 10, 'var' is a restricted
local variable type and cannot be used for type declarations
enum var { } //illegal
^
ParserTest.java:28: warning: as of release 10, 'var' is a restricted
local variable type and cannot be used for type declarations
@interface var { } //illegal
^
ParserTest.java:36: warning: as of release 10, 'var' is a restricted
local variable type and cannot be used for type declarations
static class var extends RuntimeException { } //illegal
^
6 warnings
More information about the compiler-dev
mailing list