@@ -18,6 +18,7 @@ information about the process, including in their change logs.
18
18
2024.01.17
19
19
- Specify that a type is 'incompatible with await', and use that to specify
20
20
a compile-time error at ` await e; ` .
21
+ - Specify which extension types are always-exhaustive.
21
22
22
23
2023.11.14
23
24
- Specify that a method declaration will shadow an otherwise "inherited"
@@ -828,6 +829,17 @@ type)*. Exhaustiveness analysis will treat such patterns as if they had
828
829
been an object pattern matching the extension type erasure of ` V ` (defined
829
830
below).
830
831
832
+ An extension type ` V ` is always-exhaustive if and only if its instantiated
833
+ representation type is always-exhaustive.
834
+
835
+ * For example, a type ` TriBool ` defined as
836
+ ` extension type TriBool(bool? _) {} ` ,
837
+ is always-exhaustive because the representation type, ` bool? ` , is.
838
+ For a declaration like ` extension type Pair<S, T>((S, T) _) {} ` , the type
839
+ ` Pair<SomeEnum, TriBool> ` is always-exhaustive because ` (SomeEnum, TriBool) `
840
+ is, and ` Pair<String, bool> ` is not always-exhaustive because ` (String, bool) `
841
+ isn't.*
842
+
831
843
* In other words, we make no attempt to hide the representation type during
832
844
the exhaustiveness analysis. The usage of such patterns is very similar to
833
845
a cast into the extension type in the sense that it provides a reference of
@@ -868,7 +880,7 @@ _is the extension type_
868
880
<code >V\< T<sub >1</sub >, .. T<sub >s</sub >> ; </code >,
869
881
and that its static type _ is an extension type_ .
870
882
871
- We say that a type ` T ` is _ incompatible with await_ if at least
883
+ We say that a type ` T ` is _ incompatible with await_ if at least
872
884
one of the following criteria holds:
873
885
874
886
- ` T ` is an extension type that does not implement ` Future ` .
@@ -877,10 +889,10 @@ one of the following criteria holds:
877
889
- ` B ` is incompatible with await, or
878
890
- ` B ` does not derive a future type, and ` X ` is
879
891
incompatible with await.
880
- - ` T ` is a type variable with bound ` S ` , and ` S ` is incompatible
892
+ - ` T ` is a type variable with bound ` S ` , and ` S ` is incompatible
881
893
with await.
882
894
883
- Consider an expression of the form ` await e ` . A compile-time error
895
+ Consider an expression of the form ` await e ` . A compile-time error
884
896
occurs if the static type of ` e ` is incompatible with await.
885
897
886
898
A compile-time error occurs if an extension type declares a member whose
@@ -911,6 +923,21 @@ types, and it is not an error to have `implements T` where `T` is a type
911
923
that denotes a ` sealed ` , ` final ` , or ` base ` class in a different library,
912
924
or ` T ` is an enumerated type.*
913
925
926
+ * Consider ` extension type E(SomeType _) implements SealedType {} `
927
+ where ` SealedType ` is a sealed type. In this situation, ` E ` does not
928
+ need to be taken into account like other immediate subtypes of ` SealedType `
929
+ (which is also the reason why we can declare it in a different library
930
+ than the library that declares ` SealedType ` ).
931
+ The representation ` SomeType ` type could be ` SealedType ` itself, in which
932
+ case ` E ` will be always-exhaustive. According to the exhaustiveness
933
+ analysis, ` E ` is just another way to spell ` SealedType ` .
934
+ ` SomeType ` could also be an immediate subtype of ` SealedType ` , in which case
935
+ ` E ` would be counted as that subtype during exhaustiveness analysis.
936
+ Finally, ` SomeType ` could be some non-immediate subtype of ` SealedType ` ,
937
+ in which case it is treated just like any other non-immediate subtype of
938
+ ` SealedType ` (they don't matter anywhere, with respect to exhaustiveness
939
+ of ` SealedType ` ).*
940
+
914
941
A compile-time error occurs if an extension type is used as a
915
942
superinterface of a class, mixin, or enum declaration, or if an extension
916
943
type is used in a mixin application as a superclass or as a mixin.
0 commit comments