Skip to content

Commit ebc2ff5

Browse files
committed
Use getFunctionArgApplyInfo in missing-unwrap diagnostic
1 parent acbf495 commit ebc2ff5

File tree

2 files changed

+2
-45
lines changed

2 files changed

+2
-45
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -757,44 +757,6 @@ bool MemberAccessOnOptionalBaseFailure::diagnoseAsError() {
757757
resultIsOptional, SourceRange());
758758
}
759759

760-
Optional<AnyFunctionType::Param>
761-
MissingOptionalUnwrapFailure::getOperatorParameterFor(Expr *expr) const {
762-
auto *parentExpr = findParentExpr(expr);
763-
if (!parentExpr)
764-
return None;
765-
766-
auto getArgIdx = [](TupleExpr *tuple, Expr *argExpr) -> unsigned {
767-
for (unsigned i = 0, n = tuple->getNumElements(); i != n; ++i) {
768-
if (tuple->getElement(i) == argExpr)
769-
return i;
770-
}
771-
llvm_unreachable("argument is not in enclosing tuple?!");
772-
};
773-
774-
auto *tupleExpr = dyn_cast<TupleExpr>(parentExpr);
775-
if (!(tupleExpr && tupleExpr->isImplicit()))
776-
return None;
777-
778-
parentExpr = findParentExpr(tupleExpr);
779-
if (!(parentExpr && isa<ApplyExpr>(parentExpr)))
780-
return None;
781-
782-
auto &cs = getConstraintSystem();
783-
auto *fnExpr = cast<ApplyExpr>(parentExpr)->getFn();
784-
if (auto overload =
785-
getOverloadChoiceIfAvailable(cs.getConstraintLocator(fnExpr))) {
786-
if (auto *decl = overload->choice.getDecl()) {
787-
if (!decl->isOperator())
788-
return None;
789-
790-
auto *fnType = overload->openedType->castTo<FunctionType>();
791-
return fnType->getParams()[getArgIdx(tupleExpr, expr)];
792-
}
793-
}
794-
795-
return None;
796-
}
797-
798760
void MissingOptionalUnwrapFailure::offerDefaultValueUnwrapFixIt(
799761
DeclContext *DC, Expr *expr) const {
800762
auto *anchor = getAnchor();
@@ -805,10 +767,9 @@ void MissingOptionalUnwrapFailure::offerDefaultValueUnwrapFixIt(
805767
if (isa<InOutExpr>(anchor))
806768
return;
807769

808-
if (auto param = getOperatorParameterFor(anchor)) {
809-
if (param->isInOut())
770+
if (auto argApplyInfo = getFunctionArgApplyInfo(getLocator()))
771+
if (argApplyInfo->getParameterFlags().isInOut())
810772
return;
811-
}
812773

813774
auto diag = emitDiagnostic(expr->getLoc(), diag::unwrap_with_default_value);
814775

lib/Sema/CSDiagnostics.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,6 @@ class MissingOptionalUnwrapFailure final : public FailureDiagnostic {
593593
void offerDefaultValueUnwrapFixIt(DeclContext *DC, Expr *expr) const;
594594
/// Suggest a force optional unwrap via `!`
595595
void offerForceUnwrapFixIt(Expr *expr) const;
596-
597-
/// Determine whether given expression is an argument used in the
598-
/// operator invocation, and if so return corresponding parameter.
599-
Optional<AnyFunctionType::Param> getOperatorParameterFor(Expr *expr) const;
600596
};
601597

602598
/// Diagnose errors associated with rvalues in positions

0 commit comments

Comments
 (0)