Skip to content

Commit c20e4ac

Browse files
committed
[Diagnostics] Fix usages of getChoiceFor
1 parent 26e51e0 commit c20e4ac

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ class ArgumentMismatchFailure : public ContextualFailure {
16211621
SourceLoc getLoc() const { return getAnchor()->getLoc(); }
16221622

16231623
ValueDecl *getDecl() const {
1624-
auto selectedOverload = getChoiceFor(getRawAnchor());
1624+
auto selectedOverload = getChoiceFor(getLocator());
16251625
if (!selectedOverload)
16261626
return nullptr;
16271627

lib/Sema/CSSimplify.cpp

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,63 +2547,6 @@ bool ConstraintSystem::repairFailures(
25472547
}
25482548
}
25492549

2550-
break;
2551-
}
2552-
2553-
case ConstraintLocator::FunctionArgument: {
2554-
auto *argLoc = getConstraintLocator(
2555-
locator.withPathElement(LocatorPathElt::SynthesizedArgument(0)));
2556-
2557-
// Let's drop the last element which points to a single argument
2558-
// and see if this is a contextual mismatch.
2559-
path.pop_back();
2560-
if (path.empty() ||
2561-
!(path.back().getKind() == ConstraintLocator::ApplyArgToParam ||
2562-
path.back().getKind() == ConstraintLocator::ContextualType))
2563-
return false;
2564-
2565-
auto arg = llvm::find_if(getTypeVariables(),
2566-
[&argLoc](const TypeVariableType *typeVar) {
2567-
return typeVar->getImpl().getLocator() == argLoc;
2568-
});
2569-
2570-
// What we have here is a form or tuple splat with no arguments
2571-
// demonstrated by following example:
2572-
//
2573-
// func foo<T: P>(_: T, _: (T.Element) -> Int) {}
2574-
// foo { 42 }
2575-
//
2576-
// In cases like this `T.Element` might be resolved to `Void`
2577-
// which means that we have to try a single empty tuple argument
2578-
// as a narrow exception to SE-0110, see `matchFunctionTypes`.
2579-
//
2580-
// But if `T.Element` didn't get resolved to `Void` we'd like
2581-
// to diagnose this as a missing argument which can't be ignored.
2582-
if (arg != getTypeVariables().end()) {
2583-
auto fnType = FunctionType::get({FunctionType::Param(lhs)},
2584-
getASTContext().TheEmptyTupleType);
2585-
conversionsOrFixes.push_back(AddMissingArguments::create(
2586-
*this, fnType, {FunctionType::Param(*arg)},
2587-
getConstraintLocator(anchor, path)));
2588-
}
2589-
2590-
if ((lhs->is<InOutType>() && !rhs->is<InOutType>()) ||
2591-
(!lhs->is<InOutType>() && rhs->is<InOutType>())) {
2592-
// We want to call matchTypes with the default decomposition options
2593-
// in case there are type variables that we couldn't bind due to the
2594-
// inout attribute mismatch.
2595-
auto result = matchTypes(lhs->getInOutObjectType(),
2596-
rhs->getInOutObjectType(), matchKind,
2597-
getDefaultDecompositionOptions(TMF_ApplyingFix),
2598-
locator);
2599-
2600-
if (result.isSuccess()) {
2601-
conversionsOrFixes.push_back(AllowInOutConversion::create(*this, lhs,
2602-
rhs, getConstraintLocator(locator)));
2603-
break;
2604-
}
2605-
}
2606-
26072550
// If parameter type is `Any` the problem might be related to
26082551
// invalid escapiness of the argument.
26092552
if (rhs->isAny())
@@ -2689,6 +2632,63 @@ bool ConstraintSystem::repairFailures(
26892632
break;
26902633
}
26912634

2635+
case ConstraintLocator::FunctionArgument: {
2636+
auto *argLoc = getConstraintLocator(
2637+
locator.withPathElement(LocatorPathElt::SynthesizedArgument(0)));
2638+
2639+
// Let's drop the last element which points to a single argument
2640+
// and see if this is a contextual mismatch.
2641+
path.pop_back();
2642+
if (path.empty() ||
2643+
!(path.back().getKind() == ConstraintLocator::ApplyArgToParam ||
2644+
path.back().getKind() == ConstraintLocator::ContextualType))
2645+
return false;
2646+
2647+
auto arg = llvm::find_if(getTypeVariables(),
2648+
[&argLoc](const TypeVariableType *typeVar) {
2649+
return typeVar->getImpl().getLocator() == argLoc;
2650+
});
2651+
2652+
// What we have here is a form or tuple splat with no arguments
2653+
// demonstrated by following example:
2654+
//
2655+
// func foo<T: P>(_: T, _: (T.Element) -> Int) {}
2656+
// foo { 42 }
2657+
//
2658+
// In cases like this `T.Element` might be resolved to `Void`
2659+
// which means that we have to try a single empty tuple argument
2660+
// as a narrow exception to SE-0110, see `matchFunctionTypes`.
2661+
//
2662+
// But if `T.Element` didn't get resolved to `Void` we'd like
2663+
// to diagnose this as a missing argument which can't be ignored.
2664+
if (arg != getTypeVariables().end()) {
2665+
auto fnType = FunctionType::get({FunctionType::Param(lhs)},
2666+
getASTContext().TheEmptyTupleType);
2667+
conversionsOrFixes.push_back(AddMissingArguments::create(
2668+
*this, fnType, {FunctionType::Param(*arg)},
2669+
getConstraintLocator(anchor, path)));
2670+
}
2671+
2672+
if ((lhs->is<InOutType>() && !rhs->is<InOutType>()) ||
2673+
(!lhs->is<InOutType>() && rhs->is<InOutType>())) {
2674+
// We want to call matchTypes with the default decomposition options
2675+
// in case there are type variables that we couldn't bind due to the
2676+
// inout attribute mismatch.
2677+
auto result = matchTypes(lhs->getInOutObjectType(),
2678+
rhs->getInOutObjectType(), matchKind,
2679+
getDefaultDecompositionOptions(TMF_ApplyingFix),
2680+
locator);
2681+
2682+
if (result.isSuccess()) {
2683+
conversionsOrFixes.push_back(AllowInOutConversion::create(*this, lhs,
2684+
rhs, getConstraintLocator(locator)));
2685+
break;
2686+
}
2687+
}
2688+
2689+
break;
2690+
}
2691+
26922692
case ConstraintLocator::TypeParameterRequirement:
26932693
case ConstraintLocator::ConditionalRequirement: {
26942694
// If dependent members are present here it's because

0 commit comments

Comments
 (0)