[ConstraintSystem] Fix regression in partial application of initializers

Correct a regression related to use of partially applied initializers,
which should be rejected only if it happens in a delegation chain.

Resolves: [SR-10837](https://bugs.swift.org/browse/SR-10837)
Resolves: rdar://problem/51442825
This commit is contained in:
Pavel Yaskevich
2019-06-05 12:13:50 -07:00
parent 61aab1daeb
commit d86ccc9741
2 changed files with 41 additions and 2 deletions

View File

@@ -1734,11 +1734,15 @@ isInvalidPartialApplication(ConstraintSystem &cs, const ValueDecl *member,
auto baseTy =
cs.simplifyType(cs.getType(anchor->getBase()))->getWithoutSpecifierType();
// Partial applications are not allowed only for constructor
// delegation, reference on the metatype is considered acceptable.
if (baseTy->is<MetatypeType>() && isa<ConstructorDecl>(member))
return {false, 0};
// If base is a metatype it would be ignored (unless this is an initializer
// call), but if it is some other type it means that we have a single
// application level already.
unsigned level =
baseTy->is<MetatypeType>() && !isa<ConstructorDecl>(member) ? 0 : 1;
unsigned level = baseTy->is<MetatypeType>() ? 0 : 1;
if (auto *call = dyn_cast_or_null<CallExpr>(cs.getParentExpr(anchor))) {
level += dyn_cast_or_null<CallExpr>(cs.getParentExpr(call)) ? 2 : 1;
}