[External] : Pattern assignment statements (extracted from: Primitive type patterns and conversions)
Brian Goetz
brian.goetz at oracle.com
Tue Mar 2 17:44:27 UTC 2021
> A couple of other things to consider:
> 1. C-style array declaration is not allowed in patterns.
Wish we could phase out C-style array decls entirely...
> 2. For local variable declaration, the initializer can omit `new int[]` part:
> int data[] = {1, 2, 3}
Good catch. For some reason I was thinking this was only for fields,
but it works for locals too. There's a future story about collection
literals, but it is unlikely we'll be able to retcon exactly this
syntax. (#include "bikeshed-deterrent.h")
We may be able to address this by including a conversion from an array
initializer to the target type of a pattern in an unconditional pattern
assignment context.
> 3. Local variable type may affect the initializer type (e.g.
> List<String> list = List.of()). What about patterns? Can we say that a
> `List<String> list` pattern is a total pattern over `List.of()`
> expression type?
Yes, patterns have a notion of a target type, which is the type they
have declared as their matchee. For a type pattern `T t`, that target
type is T. We already evaluate whether the pattern is applicable to the
matchee using this type.
More information about the amber-spec-experts
mailing list