Skip to content

Commit 315a0ad

Browse files
committed
[CSDiagnostics] Add invalid partial apply diagnostic for mutating methods
1 parent 7d830ce commit 315a0ad

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,3 +1477,13 @@ bool MissingMemberFailure::diagnoseAsError() {
14771477
corrections.noteAllCandidates();
14781478
return true;
14791479
}
1480+
1481+
bool PartialApplicationFailure::diagnoseAsError() {
1482+
auto *anchor = cast<UnresolvedDotExpr>(getRawAnchor());
1483+
auto diagnostic = CompatibilityWarning
1484+
? diag::partial_application_of_function_invalid_swift4
1485+
: diag::partial_application_of_function_invalid;
1486+
1487+
emitDiagnostic(anchor->getNameLoc(), diagnostic, RefKind::MutatingMethod);
1488+
return true;
1489+
}

lib/Sema/CSDiagnostics.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,23 @@ class MissingMemberFailure final : public FailureDiagnostic {
674674
DeclName memberName);
675675
};
676676

677+
class PartialApplicationFailure final : public FailureDiagnostic {
678+
enum RefKind : unsigned {
679+
MutatingMethod,
680+
SuperInit,
681+
SelfInit,
682+
};
683+
684+
bool CompatibilityWarning;
685+
686+
public:
687+
PartialApplicationFailure(Expr *root, bool warning, ConstraintSystem &cs,
688+
ConstraintLocator *locator)
689+
: FailureDiagnostic(root, cs, locator), CompatibilityWarning(warning) {}
690+
691+
bool diagnoseAsError() override;
692+
};
693+
677694
} // end namespace constraints
678695
} // end namespace swift
679696

lib/Sema/CSFix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ DefineMemberBasedOnUse::create(ConstraintSystem &cs, Type baseType,
260260
}
261261

262262
bool AllowInvalidPartialApplication::diagnose(Expr *root, bool asNote) const {
263-
return false;
263+
auto failure = PartialApplicationFailure(root, isWarning(),
264+
getConstraintSystem(), getLocator());
265+
return failure.diagnose(asNote);
264266
}
265267

266268
AllowInvalidPartialApplication *

0 commit comments

Comments
 (0)