Skip to content

Commit 5001616

Browse files
authored
Spec null-safety combined member signature and spread type
This PR adds a specification of combined member signatures (with null-safety: based on NNBD_TOP_MERGE). It also adds a specification of how to find the element, key, and value types for a `<spreadElement>` of the form `...e` or `...?e` where the type of `e` is `Null` or a subtype. Merge pull request #1079 from dart-lang/nnbd_spec_spread_combined_jul20.
2 parents 2a8bff5 + 17ea543 commit 5001616

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

accepted/future-releases/nnbd/feature-specification.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ Status: Draft
66

77
## CHANGELOG
88

9-
2020..06.02
9+
2020.07.09
10+
- Specify combined member signature and spread element typing
11+
with null-safety.
12+
13+
2020.06.02
1014
- Fix the diff to the spec for potentially constant instance checks
1115
- Specify that extensions do not apply to values of type `Never`
1216
- Specify the treatment of typedefs from legacy libraries
@@ -679,6 +683,22 @@ If no type is specified in a catch clause, then the default type of the error
679683
variable is `Object`, instead of `dynamic` as was the case in pre-null safe
680684
Dart.
681685

686+
#### Spread element typing
687+
688+
In a collection literal in Dart before null-safety, the inferred element
689+
type of a spread element of the form `...?e` where `e` has static type
690+
`Null` is `Null`, and so are the inferred key type and value type.
691+
692+
With null-safety, when the static type of `e` is `Null` or a potentially
693+
nullable subtype thereof, the inferred element, key, and value type
694+
of `...?e` is `Never`.
695+
696+
Similarly, when the static type of `e` is a subtype of `Never`,
697+
the element, key, and value type of `...e` and `...?e` is `Never`.
698+
699+
*When the static type _S_ of `e` is strictly non-nullable, such as when _S_
700+
is `Never`, `...?e` is a warning, but it may still occur.*
701+
682702
### Instantiate to bounds
683703

684704
The computation of instantiation to bounds is changed to substitute `Never` for
@@ -731,6 +751,25 @@ subtype of `S`.
731751

732752
The default bound of generic type parameters is treated as `Object?`.
733753

754+
### Combined member signatures
755+
756+
[This section](https://github.com/dart-lang/language/blob/9e12517922c1f0021aead2af163c3b502497f312/specification/dartLangSpec.tex#L4241)
757+
in the language specification defines the notion of a _combined member
758+
signature_. In Dart before null-safety it is based on the textually first
759+
superinterface that has a most specific signature. With null-safety it
760+
is changed such that the all the most specific signatures are merged.
761+
762+
This is achieved by changing
763+
[this paragraph](https://github.com/dart-lang/language/blob/9e12517922c1f0021aead2af163c3b502497f312/specification/dartLangSpec.tex#L4373)
764+
to the following:
765+
766+
"Let _m<sub>all</sub>_ be the result of applying `NNBD_TOP_MERGE` to
767+
the elements in _M<sub>all</sub>_, ordered according to the interface
768+
_I<sub>1</sub> .. I<sub>k</sub>_ that each signature came from."
769+
770+
Moreover, the occurrence of _m<sub>i</sub>_ in the next paragraph is
771+
changed to _m<sub>all</sub>_.
772+
734773
### Implicit conversions
735774

736775
The implicit conversion of integer literals to double literals is performed when

0 commit comments

Comments
 (0)