Skip to content

Commit ade528c

Browse files
committed
Fixed the type alias omission in the def. of simple bounds
Cf. SDK issue 34722, where the need for this clarification arose. Change-Id: I3b1692931506410e77c59004b1ed1981a17a6f3d Reviewed-on: https://dart-review.googlesource.com/c/78982 Reviewed-by: Leaf Petersen <[email protected]>
1 parent ddf6777 commit ade528c

1 file changed

Lines changed: 42 additions & 9 deletions

File tree

docs/language/informal/instantiate-to-bound.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,42 @@ This mechanism does not require any grammar modifications.
9999

100100
## Static analysis
101101

102-
Let _G_ be a generic class or parameterized type alias with formal type
103-
parameter declarations
104-
_F<sub>1</sub> .. F<sub>k</sub>_ containing formal type parameters
102+
We will define simple bounds, but at first we need an auxiliary concept.
103+
Let _T_ be a type of the form `typeName`. A type _S_ then _contains_ _T_
104+
if one of the following conditions hold:
105+
106+
- _S_ is of the form `typeName`, and _S_ is _T_.
107+
- _S_ is of the form `typeName typeArguments`, and one of the type
108+
arguments contains _T_.
109+
- _S_ is of the form `typeName typeArguments?` where `typeName` denotes a
110+
type alias _F_, and the body of _F_ contains _T_.
111+
- _S_ is of the form
112+
`returnType? 'Function' typeParameters? parameterTypeList` and
113+
`returnType?` contains _T_, or a bound in `typeParameters?` contains _T_,
114+
or the type of a parameter in `parameterTypeList` contains _T_.
115+
116+
*Multiple cases may be applicable, e.g., when a type alias is applied to a
117+
list of actual type arguments, and the type alias body as well as some type
118+
arguments may contain _T_.*
119+
120+
*In the rule about type aliases, _F_ may or may not be parameterized, and
121+
it may or may not receive type arguments. However, there is no need to
122+
consider the result of substituting actual type arguments for formal type
123+
parameters in the body of the type alias, because we only need to inspect
124+
all types of the form `typeName` contained in its body, and they are not
125+
affected by such a substitution.*
126+
127+
*It is understood that name capture is avoided, that is, a type _S_ does
128+
not contain `p.C` even if _S_ contains `F` which denotes a type alias whose
129+
body contains the syntax `p.C`, say, as a return type, if `p` has different
130+
meanings in _S_ and in the body of _F_. This could occur because _S_ and
131+
_F_ are declared in different libraries. Similarly, when a type parameter
132+
bound _B_ contains a type variable `X` from the enclosing class, it is
133+
never because `X` is contained in the body of a type alias, it will always
134+
be as a syntactic subterm of _B_.*
135+
136+
Let _G_ be a generic class or parameterized type alias with _k_ formal type
137+
parameter declarations containing formal type parameters
105138
_X<sub>1</sub> .. X<sub>k</sub>_ and bounds
106139
_B<sub>1</sub> .. B<sub>k</sub>_. We say that the formal type parameter
107140
_X<sub>j</sub>_ has a _simple bound_ when one of the following requirements
@@ -110,8 +143,8 @@ is satisfied:
110143
1. _B<sub>j</sub>_ is omitted.
111144

112145
2. _B<sub>j</sub>_ is included, but does not contain any of _X<sub>1</sub>
113-
.. X<sub>k</sub>_. If _B<sub>j</sub>_ contains a type _T_ on the form
114-
`qualified` (*for instance, `C` or `p.D`*) which denotes a generic class
146+
.. X<sub>k</sub>_. If _B<sub>j</sub>_ contains a type _T_ of the form
147+
`typeName` (*for instance, `C` or `p.D`*) which denotes a generic class
115148
or parameterized type alias _G<sub>1</sub>_ (*that is, _T_ is a raw type*),
116149
every type argument of _G<sub>1</sub>_ has a simple bound.
117150

@@ -130,7 +163,7 @@ involved types to be "simple enough". We impose the following constraint on
130163
all bounds because any generic type may be used as a raw type.*
131164

132165
It is a compile-time error if a formal parameter bound _B_ contains a type
133-
_T_ on the form `qualified` and _T_ denotes a generic class or parameterized
166+
_T_ on the form `typeName` and _T_ denotes a generic class or parameterized
134167
type alias _G_ (*that is, _T_ is a raw type*), unless every formal type
135168
parameter of _G_ has a simple bound.
136169

@@ -140,7 +173,7 @@ compile-time error because the bound `C` is raw, and the formal type
140173
parameter `X` that corresponds to the omitted type argument does not have a
141174
simple bound.*
142175

143-
When a type annotation _T_ on the form `qualified` denotes a generic class
176+
When a type annotation _T_ on the form `typeName` denotes a generic class
144177
or parameterized type alias (*so _T_ is raw*), instantiate to bound is used
145178
to provide the missing type argument list. It is a compile-time error if
146179
the instantiate to bound process fails.
@@ -157,7 +190,7 @@ bound would still be used in cases where no information is available to
157190
infer the omitted type arguments, e.g., for `List xs = [];`.*
158191

159192
*When type inference is providing actual type arguments for a term _G_ on
160-
the form `qualified` which denotes a generic class or a parameterized type
193+
the form `typeName` which denotes a generic class or a parameterized type
161194
alias, instantiate to bound may be used to provide the value for type
162195
arguments where no information is available for inferring such an actual
163196
type argument. This document does not specify how inference interacts with
@@ -166,7 +199,7 @@ of inference. We will hence proceed to specify instantiate to bound as it
166199
applies to a type argument list which is omitted, such that a value for all
167200
the actual type arguments must be computed.*
168201

169-
Let _T_ be a `qualified` term which denotes a generic class or
202+
Let _T_ be a `typeName` term which denotes a generic class or
170203
parameterized type alias _G_ (*so _T_ is a raw type*), let
171204
_F<sub>1</sub> .. F<sub>k</sub>_ be the formal type
172205
parameter declarations in the declaration of _G_, with type parameters

0 commit comments

Comments
 (0)