Skip to content
Merged
2 changes: 1 addition & 1 deletion lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7381,7 +7381,7 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
ArrayRef<ConstraintFix *> secondaryFixes{fixes.begin() + 1, fixes.end()};

auto *coalescedFix = primaryFix->coalescedWith(secondaryFixes);
auto diagnosed = coalescedFix->diagnose(root);
auto diagnosed = coalescedFix->diagnose();
if (coalescedFix->isWarning()) {
assert(diagnosed && "warnings should always be diagnosed");
(void)diagnosed;
Expand Down
30 changes: 15 additions & 15 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults(

// If we found no results at all, mention that fact.
if (result.UnviableCandidates.empty()) {
MissingMemberFailure failure(nullptr, CS, baseObjTy, memberName,
MissingMemberFailure failure(CS, baseObjTy, memberName,
CS.getConstraintLocator(E));
auto diagnosed = failure.diagnoseAsError();
assert(diagnosed && "Failed to produce missing member diagnostic");
Expand Down Expand Up @@ -513,7 +513,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults(

case MemberLookupResult::UR_UnavailableInExistential: {
InvalidMemberRefOnExistential failure(
baseExpr, CS, instanceTy, memberName, CS.getConstraintLocator(E));
CS, instanceTy, memberName, CS.getConstraintLocator(E));
failure.diagnoseAsError();
return;
}
Expand All @@ -524,7 +524,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults(
? ConstraintLocator::SubscriptMember
: ConstraintLocator::Member;
AllowTypeOrInstanceMemberFailure failure(
expr, CS, baseObjTy, choice->getDecl(), memberName,
CS, baseObjTy, choice->getDecl(), memberName,
CS.getConstraintLocator(E, locatorKind));
auto diagnosed = failure.diagnoseAsError();
assert(diagnosed &&
Expand All @@ -534,7 +534,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults(
}
case MemberLookupResult::UR_MutatingMemberOnRValue:
case MemberLookupResult::UR_MutatingGetterOnRValue: {
MutatingMemberRefOnImmutableBase failure(E, CS, choice->getDecl(),
MutatingMemberRefOnImmutableBase failure(CS, choice->getDecl(),
CS.getConstraintLocator(E));
(void)failure.diagnose();
return;
Expand All @@ -548,7 +548,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults(
// visible to us, but the conforming type is. In this case, we need to
// clamp the formal access for diagnostics purposes to the formal access
// of the protocol itself.
InaccessibleMemberFailure failure(expr, CS, choice->getDecl(),
InaccessibleMemberFailure failure(CS, choice->getDecl(),
CS.getConstraintLocator(E));
auto diagnosed = failure.diagnoseAsError();
assert(diagnosed && "failed to produce expected diagnostic");
Expand Down Expand Up @@ -730,7 +730,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
if (auto fromTT = fromType->getAs<TupleType>())
if (auto toTT = toType->getAs<TupleType>()) {
if (fromTT->getNumElements() != toTT->getNumElements()) {
auto failure = TupleContextualFailure(anchor, CS, fromTT, toTT,
auto failure = TupleContextualFailure(CS, fromTT, toTT,
CS.getConstraintLocator(expr));
return failure.diagnoseAsError();
}
Expand All @@ -748,7 +748,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
// then we have a type error.
if (computeTupleShuffle(TEType->castTo<TupleType>()->getElements(),
toTT->getElements(), sources)) {
auto failure = TupleContextualFailure(anchor, CS, fromTT, toTT,
auto failure = TupleContextualFailure(CS, fromTT, toTT,
CS.getConstraintLocator(expr));
return failure.diagnoseAsError();
}
Expand All @@ -766,7 +766,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){


// Check for various issues converting to Bool.
ContextualFailure failure(expr, CS, fromType, toType,
ContextualFailure failure(CS, fromType, toType,
constraint->getLocator());
if (failure.diagnoseConversionToBool())
return true;
Expand Down Expand Up @@ -1285,7 +1285,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
return false;

ContextualFailure failure(
expr, CS, CTP, exprType, contextualType,
CS, CTP, exprType, contextualType,
CS.getConstraintLocator(expr, LocatorPathElt::ContextualType()));
return failure.diagnoseAsError();
}
Expand Down Expand Up @@ -2877,7 +2877,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
LocatorPathElt::ApplyArgToParam(0, 0, flags)},
/*summaryFlags=*/0);

ArgumentMismatchFailure failure(expr, CS, lhsType, rhsType, locator);
ArgumentMismatchFailure failure(CS, lhsType, rhsType, locator);
return failure.diagnosePatternMatchingMismatch();
}

Expand Down Expand Up @@ -3133,7 +3133,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
// destructuring and provide a proper fix-it.
if (argTupleTy->getNumElements() == actualArgCount) {
ClosureParamDestructuringFailure failure(
expr, CS, fnType, CS.getConstraintLocator(CE));
CS, fnType, CS.getConstraintLocator(CE));
return failure.diagnoseAsError();
}
}
Expand Down Expand Up @@ -3312,7 +3312,7 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
return false;
}

ContextualFailure failure(expr, CS, CS.getType(E), contextualType,
ContextualFailure failure(CS, CS.getType(E), contextualType,
CS.getConstraintLocator(E));
if (failure.diagnoseConversionToDictionary())
return true;
Expand Down Expand Up @@ -3581,7 +3581,7 @@ bool FailureDiagnosis::diagnoseMemberFailures(
if (auto baseFTy = baseObjTy->getAs<AnyFunctionType>()) {
if (baseExpr && baseFTy->getParams().empty()) {
auto failure =
MissingCallFailure(expr, CS, CS.getConstraintLocator(baseExpr));
MissingCallFailure(CS, CS.getConstraintLocator(baseExpr));
return failure.diagnoseAsError();
}
}
Expand Down Expand Up @@ -3720,7 +3720,7 @@ bool FailureDiagnosis::diagnoseMemberFailures(

if (!optionalResult.ViableCandidates.empty()) {
MemberAccessOnOptionalBaseFailure failure(
expr, CS, CS.getConstraintLocator(baseExpr), memberName,
CS, CS.getConstraintLocator(baseExpr), memberName,
/*resultOptional=*/false);
return failure.diagnoseAsError();
}
Expand Down Expand Up @@ -4224,7 +4224,7 @@ void FailureDiagnosis::diagnoseAmbiguity(Expr *E) {
{
bool diagnosed = false;
for (auto *fix : CS.getFixes())
diagnosed |= fix->diagnose(expr);
diagnosed |= fix->diagnose();

if (diagnosed)
return;
Expand Down
30 changes: 17 additions & 13 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ FailureDiagnostic::emitDiagnostic(ArgTypes &&... Args) const {
}

Expr *FailureDiagnostic::findParentExpr(Expr *subExpr) const {
return E ? E->getParentMap()[subExpr] : nullptr;
return CS.getParentExpr(subExpr);
}

Expr *
Expand Down Expand Up @@ -680,7 +680,7 @@ bool MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef() {
// about missing conformance just in case.
auto operatorID = name.getIdentifier();

auto *applyExpr = cast<ApplyExpr>(findParentExpr(anchor));
auto *applyExpr = cast_or_null<ApplyExpr>(findParentExpr(anchor));
if (auto *binaryOp = dyn_cast<BinaryExpr>(applyExpr)) {
auto lhsType = getType(binaryOp->getArg()->getElement(0));
auto rhsType = getType(binaryOp->getArg()->getElement(1));
Expand Down Expand Up @@ -1048,7 +1048,10 @@ bool MissingExplicitConversionFailure::diagnoseAsError() {
if (!useAs && !useAsBang)
return false;

auto *expr = getParentExpr();
auto *expr = findParentExpr(getAnchor());
if (!expr)
expr = getAnchor();

// If we're performing pattern matching,
// "as" means something completely different...
if (auto binOpExpr = dyn_cast<BinaryExpr>(expr)) {
Expand Down Expand Up @@ -1146,8 +1149,9 @@ void MissingOptionalUnwrapFailure::offerDefaultValueUnwrapFixIt(
// Figure out what we need to parenthesize.
bool needsParensInside =
exprNeedsParensBeforeAddingNilCoalescing(DC, expr);
auto parentExpr = findParentExpr(anchor);
bool needsParensOutside =
exprNeedsParensAfterAddingNilCoalescing(DC, expr, getParentExpr());
exprNeedsParensAfterAddingNilCoalescing(DC, expr, parentExpr);

llvm::SmallString<2> insertBefore;
llvm::SmallString<32> insertAfter;
Expand Down Expand Up @@ -1488,8 +1492,8 @@ bool TypeChecker::diagnoseSelfAssignment(const Expr *expr) {
}

bool TrailingClosureAmbiguityFailure::diagnoseAsNote() {
const auto *expr = getParentExpr();
auto *callExpr = dyn_cast<CallExpr>(expr);
const auto *expr = findParentExpr(getAnchor());
auto *callExpr = dyn_cast_or_null<CallExpr>(expr);
if (!callExpr)
return false;
if (!callExpr->hasTrailingClosure())
Expand Down Expand Up @@ -1542,19 +1546,19 @@ bool TrailingClosureAmbiguityFailure::diagnoseAsNote() {

AssignmentFailure::AssignmentFailure(Expr *destExpr, ConstraintSystem &cs,
SourceLoc diagnosticLoc)
: FailureDiagnostic(destExpr, cs, cs.getConstraintLocator(destExpr)),
: FailureDiagnostic(cs, cs.getConstraintLocator(destExpr)),
DestExpr(destExpr),
Loc(diagnosticLoc),
DeclDiagnostic(findDeclDiagonstic(cs.getASTContext(), destExpr)),
TypeDiagnostic(diag::assignment_lhs_not_lvalue) {}

bool AssignmentFailure::diagnoseAsError() {
auto &cs = getConstraintSystem();
auto *DC = getDC();
auto *destExpr = getParentExpr();

// Walk through the destination expression, resolving what the problem is. If
// we find a node in the lvalue path that is problematic, this returns it.
auto immInfo = resolveImmutableBase(destExpr);
auto immInfo = resolveImmutableBase(DestExpr);

Optional<OverloadChoice> choice = immInfo.second;

Expand Down Expand Up @@ -1755,7 +1759,7 @@ bool AssignmentFailure::diagnoseAsError() {
return true;
}

emitDiagnostic(Loc, TypeDiagnostic, getType(destExpr))
emitDiagnostic(Loc, TypeDiagnostic, getType(DestExpr))
.highlight(immInfo.first->getSourceRange());
return true;
}
Expand Down Expand Up @@ -3339,7 +3343,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
return true;
}

Expr *expr = getParentExpr();
Expr *expr = findParentExpr(getAnchor());
SourceRange baseRange = expr ? expr->getSourceRange() : SourceRange();

// If the base is an implicit self type reference, and we're in a
Expand Down Expand Up @@ -3552,7 +3556,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
// components, let's provide a tailored diagnostic and return because
// that is unsupported so there is no fix-it.
if (locator->isForKeyPathComponent()) {
InvalidStaticMemberRefInKeyPath failure(expr, cs, Member, locator);
InvalidStaticMemberRefInKeyPath failure(cs, Member, locator);
return failure.diagnoseAsError();
}

Expand Down Expand Up @@ -5532,7 +5536,7 @@ bool ArgumentMismatchFailure::diagnoseMisplacedMissingArgument() const {
auto *anchor = getRawAnchor();

MissingArgumentsFailure failure(
getParentExpr(), cs, {param.withType(argType)},
cs, {param.withType(argType)},
cs.getConstraintLocator(anchor, ConstraintLocator::ApplyArgument));

return failure.diagnoseSingleMissingArgument();
Expand Down
Loading