[External] : Re: Primitive type patterns
forax at univ-mlv.fr
forax at univ-mlv.fr
Mon Feb 28 12:50:38 UTC 2022
From: "Brian Goetz" <brian.goetz at oracle.com>
To: "Remi Forax" <forax at univ-mlv.fr>
Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
Sent: Saturday, February 26, 2022 5:49:08 PM
Subject: Re: [External] : Re: Primitive type patterns
BQ_BEGIN
BQ_BEGIN
BQ_BEGIN
#### Relationship with assignment context
BQ_END
That's a huge leap, let's take a step back.
I see two questions that should be answered first.
1) do we really want pattern in case of assignment/declaration to support assignment conversions ?
2) do we want patterns used by the switch or instanceof to follow the exact same rules as patterns used in assignment/declaration ?
BQ_END
BQ_END
[...]
BQ_BEGIN
BQ_BEGIN
2) we already know that depending on the context (inside a switch, inside a instanceof, inside an assignment) the rules for pattern are not exactly the same.
BQ_END
OMG Remi, would you please stop repeating this incorrect claim. The rules for pattern matching are exactly the same across contexts; the differences are that the contexts get to choose when to try to match, and what to do if nothing matches.
BQ_END
if (o instanceof Circle(Point(int x, int y), int radius))
means
if (o instanceof Circle circle) {
Point center = circle.center();
if (center == null) {
goto end
}
int x = center.x();
int y = center.y();
int radius = circle.radius();
end:
}
while
Circle(Point(int x, int y), int radius) = c;
means
Point center = circle.center();
if (center == null) {
throw new NPE()
}
int x = center.x();
int y = center.y();
int radius = circle.radius();
end:
In the context of switch or instanceof, a pattern does not have to be total, while in case of a assignment the pattern has to be total,
so depending on the context, the semantics is different.
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20220228/d3842c80/attachment.htm>
More information about the amber-spec-experts
mailing list