@@ -195,6 +195,101 @@ class FailureDiagnostic {
195
195
std::pair<Expr *, bool > computeAnchor () const ;
196
196
};
197
197
198
+ // / Provides information about the application of a function argument to a
199
+ // / parameter.
200
+ class FunctionArgApplyInfo {
201
+ Expr *ArgExpr;
202
+ unsigned ArgIdx;
203
+ Type ArgType;
204
+
205
+ unsigned ParamIdx;
206
+
207
+ Type FnInterfaceType;
208
+ FunctionType *FnType;
209
+ const ValueDecl *Callee;
210
+
211
+ public:
212
+ FunctionArgApplyInfo (Expr *argExpr, unsigned argIdx, Type argType,
213
+ unsigned paramIdx, Type fnInterfaceType,
214
+ FunctionType *fnType, const ValueDecl *callee)
215
+ : ArgExpr(argExpr), ArgIdx(argIdx), ArgType(argType), ParamIdx(paramIdx),
216
+ FnInterfaceType (fnInterfaceType), FnType(fnType), Callee(callee) {}
217
+
218
+ // / \returns The argument being applied.
219
+ Expr *getArgExpr () const { return ArgExpr; }
220
+
221
+ // / \returns The position of the argument, starting at 1.
222
+ unsigned getArgPosition () const { return ArgIdx + 1 ; }
223
+
224
+ // / \returns The position of the parameter, starting at 1.
225
+ unsigned getParamPosition () const { return ParamIdx + 1 ; }
226
+
227
+ // / \returns The type of the argument being applied, including any generic
228
+ // / substitutions.
229
+ // /
230
+ // / \param withSpecifier Whether to keep the inout or @lvalue specifier of
231
+ // / the argument, if any.
232
+ Type getArgType (bool withSpecifier = false ) const {
233
+ return withSpecifier ? ArgType : ArgType->getWithoutSpecifierType ();
234
+ }
235
+
236
+ // / \returns The interface type for the function being applied. Note that this
237
+ // / may not a function type, for example it could be a generic parameter.
238
+ Type getFnInterfaceType () const { return FnInterfaceType; }
239
+
240
+ // / \returns The function type being applied, including any generic
241
+ // / substitutions.
242
+ FunctionType *getFnType () const { return FnType; }
243
+
244
+ // / \returns The callee for the application.
245
+ const ValueDecl *getCallee () const { return Callee; }
246
+
247
+ private:
248
+ Type getParamTypeImpl (AnyFunctionType *fnTy,
249
+ bool lookThroughAutoclosure) const {
250
+ auto param = fnTy->getParams ()[ParamIdx];
251
+ auto paramTy = param.getPlainType ();
252
+ if (lookThroughAutoclosure && param.isAutoClosure ())
253
+ paramTy = paramTy->castTo <FunctionType>()->getResult ();
254
+ return paramTy;
255
+ }
256
+
257
+ public:
258
+ // / \returns The type of the parameter which the argument is being applied to,
259
+ // / including any generic substitutions.
260
+ // /
261
+ // / \param lookThroughAutoclosure Whether an @autoclosure () -> T parameter
262
+ // / should be treated as being of type T.
263
+ Type getParamType (bool lookThroughAutoclosure = true ) const {
264
+ return getParamTypeImpl (FnType, lookThroughAutoclosure);
265
+ }
266
+
267
+ // / \returns The interface type of the parameter which the argument is being
268
+ // / applied to.
269
+ // /
270
+ // / \param lookThroughAutoclosure Whether an @autoclosure () -> T parameter
271
+ // / should be treated as being of type T.
272
+ Type getParamInterfaceType (bool lookThroughAutoclosure = true ) const {
273
+ auto interfaceFnTy = FnInterfaceType->getAs <AnyFunctionType>();
274
+ if (!interfaceFnTy) {
275
+ // If the interface type isn't a function, then just return the resolved
276
+ // parameter type.
277
+ return getParamType (lookThroughAutoclosure)->mapTypeOutOfContext ();
278
+ }
279
+ return getParamTypeImpl (interfaceFnTy, lookThroughAutoclosure);
280
+ }
281
+
282
+ // / \returns The flags of the parameter which the argument is being applied
283
+ // / to.
284
+ ParameterTypeFlags getParameterFlags () const {
285
+ return FnType->getParams ()[ParamIdx].getParameterFlags ();
286
+ }
287
+
288
+ ParameterTypeFlags getParameterFlagsAtIndex (unsigned idx) const {
289
+ return FnType->getParams ()[idx].getParameterFlags ();
290
+ }
291
+ };
292
+
198
293
// / Base class for all of the diagnostics related to generic requirement
199
294
// / failures, provides common information like failed requirement,
200
295
// / declaration where such requirement comes from, etc.
@@ -1649,101 +1744,6 @@ class ExpandArrayIntoVarargsFailure final : public ContextualFailure {
1649
1744
void tryDropArrayBracketsFixIt (Expr *anchor) const ;
1650
1745
};
1651
1746
1652
- // / Provides information about the application of a function argument to a
1653
- // / parameter.
1654
- class FunctionArgApplyInfo {
1655
- Expr *ArgExpr;
1656
- unsigned ArgIdx;
1657
- Type ArgType;
1658
-
1659
- unsigned ParamIdx;
1660
-
1661
- Type FnInterfaceType;
1662
- FunctionType *FnType;
1663
- const ValueDecl *Callee;
1664
-
1665
- public:
1666
- FunctionArgApplyInfo (Expr *argExpr, unsigned argIdx, Type argType,
1667
- unsigned paramIdx, Type fnInterfaceType,
1668
- FunctionType *fnType, const ValueDecl *callee)
1669
- : ArgExpr(argExpr), ArgIdx(argIdx), ArgType(argType), ParamIdx(paramIdx),
1670
- FnInterfaceType (fnInterfaceType), FnType(fnType), Callee(callee) {}
1671
-
1672
- // / \returns The argument being applied.
1673
- Expr *getArgExpr () const { return ArgExpr; }
1674
-
1675
- // / \returns The position of the argument, starting at 1.
1676
- unsigned getArgPosition () const { return ArgIdx + 1 ; }
1677
-
1678
- // / \returns The position of the parameter, starting at 1.
1679
- unsigned getParamPosition () const { return ParamIdx + 1 ; }
1680
-
1681
- // / \returns The type of the argument being applied, including any generic
1682
- // / substitutions.
1683
- // /
1684
- // / \param withSpecifier Whether to keep the inout or @lvalue specifier of
1685
- // / the argument, if any.
1686
- Type getArgType (bool withSpecifier = false ) const {
1687
- return withSpecifier ? ArgType : ArgType->getWithoutSpecifierType ();
1688
- }
1689
-
1690
- // / \returns The interface type for the function being applied. Note that this
1691
- // / may not a function type, for example it could be a generic parameter.
1692
- Type getFnInterfaceType () const { return FnInterfaceType; }
1693
-
1694
- // / \returns The function type being applied, including any generic
1695
- // / substitutions.
1696
- FunctionType *getFnType () const { return FnType; }
1697
-
1698
- // / \returns The callee for the application.
1699
- const ValueDecl *getCallee () const { return Callee; }
1700
-
1701
- private:
1702
- Type getParamTypeImpl (AnyFunctionType *fnTy,
1703
- bool lookThroughAutoclosure) const {
1704
- auto param = fnTy->getParams ()[ParamIdx];
1705
- auto paramTy = param.getPlainType ();
1706
- if (lookThroughAutoclosure && param.isAutoClosure ())
1707
- paramTy = paramTy->castTo <FunctionType>()->getResult ();
1708
- return paramTy;
1709
- }
1710
-
1711
- public:
1712
- // / \returns The type of the parameter which the argument is being applied to,
1713
- // / including any generic substitutions.
1714
- // /
1715
- // / \param lookThroughAutoclosure Whether an @autoclosure () -> T parameter
1716
- // / should be treated as being of type T.
1717
- Type getParamType (bool lookThroughAutoclosure = true ) const {
1718
- return getParamTypeImpl (FnType, lookThroughAutoclosure);
1719
- }
1720
-
1721
- // / \returns The interface type of the parameter which the argument is being
1722
- // / applied to.
1723
- // /
1724
- // / \param lookThroughAutoclosure Whether an @autoclosure () -> T parameter
1725
- // / should be treated as being of type T.
1726
- Type getParamInterfaceType (bool lookThroughAutoclosure = true ) const {
1727
- auto interfaceFnTy = FnInterfaceType->getAs <AnyFunctionType>();
1728
- if (!interfaceFnTy) {
1729
- // If the interface type isn't a function, then just return the resolved
1730
- // parameter type.
1731
- return getParamType (lookThroughAutoclosure)->mapTypeOutOfContext ();
1732
- }
1733
- return getParamTypeImpl (interfaceFnTy, lookThroughAutoclosure);
1734
- }
1735
-
1736
- // / \returns The flags of the parameter which the argument is being applied
1737
- // / to.
1738
- ParameterTypeFlags getParameterFlags () const {
1739
- return FnType->getParams ()[ParamIdx].getParameterFlags ();
1740
- }
1741
-
1742
- ParameterTypeFlags getParameterFlagsAtIndex (unsigned idx) const {
1743
- return FnType->getParams ()[idx].getParameterFlags ();
1744
- }
1745
- };
1746
-
1747
1747
// / Diagnose a situation there is a mismatch between argument and parameter
1748
1748
// / types e.g.:
1749
1749
// /
0 commit comments