JLS primitive type in patterns draft

Angelos Bimpoudis angelos.bimpoudis at oracle.com
Tue Oct 10 15:26:22 UTC 2023


Thank you for the review, Maurizio. I addressed your comments.
* `Otherwise, if both S and P are primitive types, then:` - does this section have to spell out all cases? Or can we say that, again we just issue `x instanceof P` and then we explain how this behaves somewhere else (e.g. in chapter 15) ?
Exactness (5.5.1) is referenced from two points: 15.20.2 and 14.30.3. That is the rationale for not concentrating part of exactness in chapter 15.

The new (latest) URL now includes the JEP number:

https://cr.openjdk.org/~abimpoudis/instanceof/jep443-20231010/specs/instanceof-jls.html

Many thanks!
________________________________
From: Maurizio Cimadamore <maurizio.cimadamore at oracle.com>
Sent: 02 October 2023 18:44
To: Angelos Bimpoudis <angelos.bimpoudis at oracle.com>; amber-spec-experts <amber-spec-experts at openjdk.java.net>
Subject: JLS primitive type in patterns draft


Hi Aggelos, I did a pass on the primitive pattern JEP:

https://cr.openjdk.org/~abimpoudis/instanceof/instanceof-20230913/specs/instanceof-jls.html

Here are some comments:

* `A widening primitive conversion of a byte to an int is unconditionally exact. Any value that b holds is representable exactly in an int. As a result, the value of i will always represent, exactly the same information that the variable b holds:`

Here it is not very clear where does "b" comes from. It is shown in the code snippet, of course, but the text reads funny because it comes before the snippet. One simple fix would be to move the snippet around:

```
A widening primitive conversion of a byte to an int is unconditionally exact:

    byte b = ...
    int i = (int) b;

Any value that b holds is representable exactly in an int. As a result, the value of i will always represent, exactly the same information that the variable b holds.
```

* `A conversion C from a type S to a type P for a value x is exact if ...` - I presume you mean that "x" has type S ? If so, would be helpful to spell it out clearly?

* `... then C is exact if the run-time test S instanceof P returns true.` - should't this be `x instanceof P` ?

* In general, when you deal with multiple conversions (e.g. boxing followed by narrowing followed by XYZ), it is not clear to me that it's worth spelling out all of the combinations? You have defined when a widening is exact. And, we are also defining when an unboxing is exact (e.g. if the source object is not null). Boxing is always exact. As for narrowing you are defining that using instanceof. So... can't we just say that any conversion that is composed of multiple exact conversions is itself exact? (if so, the text can be simplified quite a bit?)

* `... if S and P are both integral types and either of them is char,` isn't it the case that this must also be a narrowing conversion? Because if it's widening you already have said that going from any integral to any integral is also exact.

* `Otherwise, if both S and P are primitive types, then:` - does this section have to spell out all cases? Or can we say that, again we just issue `x instanceof P` and then we explain how this behaves somewhere else (e.g. in chapter 15) ?

* `An inexact conversion may either result in an exception and will not yield any value or may in no exceptions and will yield a value. In the latter case, loss of information has occured.` - this sentence seems to have some issues, especially in the second part (missing "result"?)

* `The narrowing reference conversion` -> `A narrowing reference conversion` (same for the para below)

* `P contains a pattern with a primitive type p` where do we say that e.g. `int x` covers `int` ? This para seems to be about boxing

* In 14.11.1.2, I see many references to "T", which is not introduced in this section

* "then the result is true if the value of the RelationalExpression could be cast to the primitive type exactly, and false otherwise." Maybe add a reference to the section on exact conversion?

Cheers
Maurizio

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20231010/a5da93f6/attachment-0001.htm>


More information about the amber-spec-experts mailing list