Draft JEP: Keyword Management for the Java Language
Alex Buckley
alex.buckley at oracle.com
Wed May 1 19:22:10 UTC 2019
Remi, thanks for your comments.
On 5/1/2019 5:07 AM, Remi Forax wrote:
> - for the constraints on hyphenated keywords, using int-typed
> expressions is perhaps a little too clever because the compiler has
> to provide meaningful error message for the user (and IDEs automatic
> completion of not yet fully form expressions), by example, if there
> is an hyphenated keyword new-fun, for the snippet return A::new-fun,
> the expression is not valid but there are two interpretations A::new
> - fun or A:: new-fun. I think it's better to use a grammar approach
> (which keywords can be at left side or right side of an expression).
> Also the current rule doesn't work well if in the future we want to
> introduce operator overloading.
I had some trouble understanding "using int-typed expressions is perhaps
a little too clever", because they're just examples to make a point,
while "a little too clever" is the kind of comment usually targeted at a
fundamental design decision. I think what you mean is "a little too
limiting". To spell it all out:
1. Type-correct expressions that perform subtraction are part of the
"overlap" with hyphenated keywords; and
2. Type-incorrect statements that complete abruptly are part of the
overlap too (`throw-quickly` is syntactically valid today -- it will lex
and parse if `quickly` is a numeric variable -- but it is also
semantically invalid (type error), so we COULD reclassify it as a
hyphenated keyword, but we have ALREADY decided not to, per how `throw`
is mentioned in set A); and
3. [Remi's observation] Type-incorrect expressions that perform
subtraction are part of the overlap too (`A::new-fun` is syntactically
valid today, but semantically invalid, so we COULD reclassify it as a
hyphenated keyword, but we should be consistent with #2 and forbid
`new-*` hyphenated keywords like we do for `throw-*`).
(You also raise the point that if the `-` operator could be overloaded,
then it might be semantically valid for the left operand to be a method
reference expression involving `::new`, and that would clash super-badly
with `new-*` hyphenated keywords.)
tl;dr I will add `new` to set A, and avoid so much focus there on
int-typed expressions.
> - the example total-switch in section "hyphenated keywords" is
> invalid given the constraints you give.
Oops! Removed.
Alex
More information about the jdk-dev
mailing list