@@ -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:
1101431 . _ B<sub >j</sub >_ is omitted.
111144
1121452 . _ 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
130163all bounds because any generic type may be used as a raw type.*
131164
132165It 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
134167type alias _ G_ (* that is, _ T_ is a raw type* ), unless every formal type
135168parameter of _ G_ has a simple bound.
136169
@@ -140,7 +173,7 @@ compile-time error because the bound `C` is raw, and the formal type
140173parameter ` X ` that corresponds to the omitted type argument does not have a
141174simple 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
144177or parameterized type alias (* so _ T_ is raw* ), instantiate to bound is used
145178to provide the missing type argument list. It is a compile-time error if
146179the instantiate to bound process fails.
@@ -157,7 +190,7 @@ bound would still be used in cases where no information is available to
157190infer 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
161194alias, instantiate to bound may be used to provide the value for type
162195arguments where no information is available for inferring such an actual
163196type 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
166199applies to a type argument list which is omitted, such that a value for all
167200the 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
170203parameterized type alias _ G_ (* so _ T_ is a raw type* ), let
171204_ F<sub >1</sub > .. F<sub >k</sub >_ be the formal type
172205parameter declarations in the declaration of _ G_ , with type parameters
0 commit comments