[pattern-switch] Totality
Brian Goetz
brian.goetz at oracle.com
Fri Aug 28 22:43:10 UTC 2020
>
> It's not rare to add components to a sum type, by example a MouseEvent
> is upgraded to add the number of mouse wheel scroll knobs.
(later corrected to "product")
To do that, you can't just blindly add a new component, because existing
ctor calls will no longer link. If yesterday you had
record Foo(int x, int y) { }
then if you want to add a z, you have to:
record Foo(int x, int y, int z) {
Foo(int x, int y) { this(x,y, 0); }
}
and now old ctor sites will link.
It's exactly the same with dtors; if you add a component, you have to
explicitly provide the dtor with the old descriptor.
> in my opinion, a cascade of if ... instanceof and a switch on types
> should have the same constraints
It's a good intuition, but can you be specific about what constraints
you are talking about?
More information about the amber-spec-experts
mailing list