Skip to content

Commit d77e349

Browse files
committed
[ConstraintSystem] Lift a restriction on fixing of non-function calls on Any/AnyObject
Detect and diagnose situations where call is attempted directly on `Any` or `AnyObject` or member calls with `AnyObject` base which didn't match.
1 parent a9106ca commit d77e349

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5598,6 +5598,19 @@ bool ExtraneousCallFailure::diagnoseAsError() {
55985598
}
55995599
}
56005600

5601+
if (auto *UDE = dyn_cast<UnresolvedDotExpr>(anchor)) {
5602+
auto *baseExpr = UDE->getBase();
5603+
auto *call = cast<CallExpr>(getRawAnchor());
5604+
5605+
if (getType(baseExpr)->isAnyObject()) {
5606+
emitDiagnostic(anchor->getLoc(), diag::cannot_call_with_params,
5607+
UDE->getName().getBaseName().userFacingName(),
5608+
getType(call->getArg())->getString(),
5609+
isa<TypeExpr>(baseExpr));
5610+
return true;
5611+
}
5612+
}
5613+
56015614
auto diagnostic = emitDiagnostic(
56025615
anchor->getLoc(), diag::cannot_call_non_function_value, getType(anchor));
56035616
removeParensFixIt(diagnostic);

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7520,11 +7520,6 @@ ConstraintSystem::simplifyApplicableFnConstraint(
75207520
desugar2->is<AnyMetatypeType>())
75217521
return SolutionKind::Error;
75227522

7523-
if (auto objectTy = desugar2->lookThroughAllOptionalTypes()) {
7524-
if (objectTy->isAny() || objectTy->isAnyObject())
7525-
return SolutionKind::Error;
7526-
}
7527-
75287523
// If there are any type variables associated with arguments/result
75297524
// they have to be marked as "holes".
75307525
type1.visit([&](Type subType) {

0 commit comments

Comments
 (0)