@@ -1526,30 +1526,35 @@ AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
1526
1526
// / that declared \p type. This is useful for code completion so we can match
1527
1527
// / the types we do know instead of bailing out completely because \p type
1528
1528
// / contains an error type.
1529
- static Type replaceParamErrorTypeByPlaceholder (Type type, ValueDecl *value) {
1529
+ static Type replaceParamErrorTypeByPlaceholder (Type type, ValueDecl *value, bool hasAppliedSelf ) {
1530
1530
if (!type->is <AnyFunctionType>() || !isa<AbstractFunctionDecl>(value)) {
1531
1531
return type;
1532
1532
}
1533
1533
auto funcType = type->castTo <AnyFunctionType>();
1534
1534
auto funcDecl = cast<AbstractFunctionDecl>(value);
1535
1535
1536
- auto declParams = funcDecl->getParameters ();
1536
+ SmallVector<ParamDecl *> declParams;
1537
+ if (hasAppliedSelf) {
1538
+ declParams.append (funcDecl->getParameters ()->begin (), funcDecl->getParameters ()->end ());
1539
+ } else {
1540
+ declParams.push_back (funcDecl->getImplicitSelfDecl ());
1541
+ }
1537
1542
auto typeParams = funcType->getParams ();
1538
- assert (declParams-> size () == typeParams.size ());
1543
+ assert (declParams. size () == typeParams.size ());
1539
1544
SmallVector<AnyFunctionType::Param, 4 > newParams;
1540
- newParams.reserve (declParams-> size ());
1545
+ newParams.reserve (declParams. size ());
1541
1546
for (auto i : indices (typeParams)) {
1542
1547
AnyFunctionType::Param param = typeParams[i];
1543
1548
if (param.getPlainType ()->is <ErrorType>()) {
1544
- auto paramDecl = declParams-> get (i) ;
1549
+ auto paramDecl = declParams[i] ;
1545
1550
auto placeholder =
1546
1551
PlaceholderType::get (paramDecl->getASTContext (), paramDecl);
1547
1552
newParams.push_back (param.withType (placeholder));
1548
1553
} else {
1549
1554
newParams.push_back (param);
1550
1555
}
1551
1556
}
1552
- assert (newParams.size () == declParams-> size ());
1557
+ assert (newParams.size () == declParams. size ());
1553
1558
return FunctionType::get (newParams, funcType->getResult ());
1554
1559
}
1555
1560
@@ -1620,7 +1625,7 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1620
1625
if (isForCodeCompletion () && openedType->hasError ()) {
1621
1626
// In code completion, replace error types by placeholder types so we can
1622
1627
// match the types we know instead of bailing out completely.
1623
- openedType = replaceParamErrorTypeByPlaceholder (openedType, value);
1628
+ openedType = replaceParamErrorTypeByPlaceholder (openedType, value, /* hasAppliedSelf= */ true );
1624
1629
}
1625
1630
1626
1631
// If we opened up any type variables, record the replacements.
@@ -2288,7 +2293,7 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
2288
2293
if (isForCodeCompletion () && type->hasError ()) {
2289
2294
// In code completion, replace error types by placeholder types so we can
2290
2295
// match the types we know instead of bailing out completely.
2291
- type = replaceParamErrorTypeByPlaceholder (type, value);
2296
+ type = replaceParamErrorTypeByPlaceholder (type, value, hasAppliedSelf );
2292
2297
}
2293
2298
2294
2299
return type;
0 commit comments