[External] : Re: Nullity (was: Pattern features for next iteration)
Remi Forax
forax at univ-mlv.fr
Fri Jan 22 17:20:02 UTC 2021
[...]
>> Also, what about several type patterns, like `case null, Integer _,
>> String _ -> ... // nulls, integers, and strings but no other types go
>> here`? What about `case Integer _, null, String _ ->...`?
>
> Right now, you can't say that, so it's not a problem :)
>
> I think what this speaks to is that the notion of "patterns with binding
> variables" is a little fuzzy, and needs to be tightened up a bit.
> Conceptually, what you write is reasonable and seems useful, so we
> wouldn't want to foreclose on that.
>
> Given that "case a, b, c" and "case a: case b: case c:" have no semantic
> difference now, I think we should continue with that, which suggests
> that forcing the null to come first is an arbitrary choice. Also, I
> don't see a problem with even nontrivial fallthrough here:
>
> case null:
> System.out.println("nulls are annoying");
> // fallthrough
> case Object o:
>
> I don't see any reason to outlaw this, so defining in terms of
> fallthrough is reasonable. The weird new rule is that "if a case null
> falls into a `case T t`, t is bound to null and considered DA".
It's a kind of slippery slope, null is the only possible value of the null type, so
case String:
...
// fallthrough
case Object o:
can also be seen as something reasonable.
Where should we stop ?
Rémi
More information about the amber-spec-observers
mailing list