Skip to content

Commit 640fbe6

Browse files
Fixing typos and comments
1 parent 2504f50 commit 640fbe6

File tree

5 files changed

+34
-23
lines changed

5 files changed

+34
-23
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,9 @@ class ConstraintLocatorBuilder {
868868
return (getSummaryFlags() & ConstraintLocator::IsNonEphemeralParam);
869869
}
870870

871-
/// Checks whether this locator is describing an anchor that produces a value of a
872-
/// callable type that could be implicit called using "()" either by defining
873-
/// a \c callAsFunction or by being a @dynamicCallable type.
871+
/// Checks whether this locator is describing an anchor that produces a value
872+
/// of a callable type that could be called using "()" either by defining a \c
873+
/// callAsFunction or by being a @dynamicCallable type.
874874
bool isForImplicitCallOfCallableValue() const {
875875
SmallVector<LocatorPathElt, 8> path;
876876
getLocatorParts(path);

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ CUSTOM_LOCATOR_PATH_ELT(ArgumentAttribute)
195195
/// The result of a chain of member accesses off an UnresolvedMemberExpr
196196
SIMPLE_LOCATOR_PATH_ELT(UnresolvedMemberChainResult)
197197

198-
/// A reference or expression that results in value of a callable type either @dynamicCallable
199-
/// or that defines one or more \c callAsFunction methods.
198+
/// A reference or expression that results in value of a callable type that is
199+
/// either @dynamicCallable or defines one or more \c callAsFunction methods.
200200
SIMPLE_LOCATOR_PATH_ELT(ImplicitCallOfCallableValue)
201201

202202
#undef LOCATOR_PATH_ELT

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ class MissingCallFailure final : public FailureDiagnostic {
974974

975975
bool diagnoseAsError() override;
976976

977-
/// Tailored diagnose insert an explicit call to a value of a type that
977+
/// Tailored diagnostic to insert an explicit call to a value of a type that
978978
/// supports being called either by defining a \c callAsFunction method or by
979979
/// being a @dynamicCallable type.
980980
bool diagnoseForCallableValue() const;

lib/Sema/CSSimplify.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,13 +3400,13 @@ bool ConstraintSystem::repairFailures(
34003400
auto *loc = getConstraintLocator(locator);
34013401
auto *anchor = getAsExpr(simplifyLocatorToAnchor(loc));
34023402
// In cases where we have an extension with @dynamicCallable or
3403-
// callAsFunction on types that can be expressed as literal e.g. String,
3404-
// Interger, etc. and the mismatches are let _: Int = "foo" let's prefer to
3405-
// still produce a conversion mismatch diagnostic.
3403+
// callAsFunction on types that can be expressed by a literal (e.g., String
3404+
// or Int) and the mismatches are of the form let _: Int = "foo" let's
3405+
// prefer to still produce a conversion mismatch diagnostic.
34063406
if (anchor && isa<LiteralExpr>(anchor))
34073407
return false;
34083408

3409-
// Let's attempt to see if the callable value can be explicit called to
3409+
// Let's attempt to see if the callable value can be explicitly called to
34103410
// produce the expected dstType with an ApplicableFnConstraint and record
34113411
// the fixes accordingly.
34123412
auto applyLoc = getConstraintLocator(
@@ -3744,11 +3744,14 @@ bool ConstraintSystem::repairFailures(
37443744

37453745
auto *loc = getConstraintLocator(locator);
37463746
if (getType(destExpr)->is<LValueType>() || result.isFailure()) {
3747-
// Let this asignment failure be diagnosed by the AllowTupleTypeMismatch
3747+
// Let this assignment failure be diagnosed by the AllowTupleTypeMismatch
37483748
// fix already recorded.
37493749
if (hasFixFor(loc, FixKind::AllowTupleTypeMismatch))
37503750
return true;
37513751

3752+
if (repairByInsertingExplicitCallOnCallableValue(lhs, rhs))
3753+
return true;
3754+
37523755
conversionsOrFixes.push_back(
37533756
IgnoreAssignmentDestinationType::create(*this, lhs, rhs, loc));
37543757
} else {
@@ -4019,6 +4022,9 @@ bool ConstraintSystem::repairFailures(
40194022
if (repairOutOfOrderArgumentsInBinaryFunction(*this, conversionsOrFixes,
40204023
loc))
40214024
return true;
4025+
4026+
if (repairByInsertingExplicitCallOnCallableValue(lhs, rhs))
4027+
return true;
40224028

40234029
conversionsOrFixes.push_back(
40244030
AllowArgumentMismatch::create(*this, lhs, rhs, loc));
@@ -4236,7 +4242,10 @@ bool ConstraintSystem::repairFailures(
42364242
// `lhs` - is an result type and `rhs` is a contextual type.
42374243
if (repairByConstructingRawRepresentableType(lhs, rhs))
42384244
break;
4239-
4245+
4246+
if (repairByInsertingExplicitCallOnCallableValue(lhs, rhs))
4247+
return true;
4248+
42404249
conversionsOrFixes.push_back(IgnoreContextualType::create(
42414250
*this, lhs, rhs, getConstraintLocator(locator)));
42424251
break;
@@ -8956,8 +8965,9 @@ ConstraintSystem::simplifyApplicableFnConstraint(
89568965
if (type1.getPointer() == desugar2) {
89578966
if (!isOperator || !hasInOut()) {
89588967
if (locator.isForImplicitCallOfCallableValue()) {
8959-
// This overload can be trivially called to produce a value of expected
8960-
// type record the insert explicit call fix.
8968+
// This overload has no parameters and the result type is obviously
8969+
// equivalent to the expected type, so we can record a insert explicit
8970+
// call fix for it.
89618971
if (recordFix(InsertExplicitCall::createWithResult(
89628972
*this, func1->getResult(), getConstraintLocator(locator))))
89638973
return SolutionKind::Error;
@@ -9121,13 +9131,14 @@ ConstraintSystem::simplifyApplicableFnConstraint(
91219131
.isFailure()) {
91229132
if (locator.isForImplicitCallOfCallableValue()) {
91239133
// This means overload cannot be called to produce a value of the
9124-
// expected type, so we fallback to record the actual mismatch.
9134+
// expected type, so we fall back to record the actual mismatch.
91259135
if (auto *fix = fixImplicitCallOfCallableValue(
91269136
*this, func1->getResult(), locator))
91279137
return recordFix(fix, /*impact=*/5) ? SolutionKind::Error
91289138
: SolutionKind::Solved;
91299139
}
91309140
return SolutionKind::Error;
9141+
}
91319142

91329143
if (unwrapCount == 0) {
91339144
if (locator.isForImplicitCallOfCallableValue()) {
@@ -9138,7 +9149,7 @@ ConstraintSystem::simplifyApplicableFnConstraint(
91389149
return SolutionKind::Error;
91399150
}
91409151
return SolutionKind::Solved;
9141-
9152+
}
91429153
// Record any fixes we attempted to get to the correct solution.
91439154
auto *fix = ForceOptional::create(*this, origType2, func1,
91449155
getConstraintLocator(locator));
@@ -9416,7 +9427,7 @@ ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint(
94169427
.isFailure()) {
94179428
if (locator.isForImplicitCallOfCallableValue()) {
94189429
// This dynamicCall overload cannot be called to produce a value of the
9419-
// expected type, so we fallback to record the actual mismatch.
9430+
// expected type, so we fall back to record the actual mismatch.
94209431
if (auto *fix = fixImplicitCallOfCallableValue(
94219432
*this, func1->getResult(), locator))
94229433
return recordFix(fix, /*impact=*/5) ? SolutionKind::Error

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
456456
return getConstraintLocator(anchor, newPath);
457457
}
458458
}
459-
460-
// We checkinng if it's possible to make a nominal callAsFunction callable value an
461-
// explicit call, we need to drop the inserted ApplyArgument and add the extra
462-
// apply function and implicit call to match it as the callee locator recorded when
463-
// resolving the overload.
459+
460+
// We checking if it's possible to make a nominal callAsFunction callable
461+
// value an explicit call, we need to drop the inserted ApplyArgument and add
462+
// the extra apply function and implicit call to match it as the callee
463+
// locator recorded when resolving the overload.
464464
if (locator->findLast<LocatorPathElt::ImplicitCallOfCallableValue>() &&
465465
!locator->findLast<LocatorPathElt::DynamicCallable>()) {
466466
SmallVector<LocatorPathElt, 4> newPath;
@@ -4309,7 +4309,7 @@ ConstraintSystem::getArgumentInfo(ConstraintLocator *locator) {
43094309
return None;
43104310

43114311
// Since we are only attempting to check if it's possible to insert an
4312-
// explicit call in an anchor expr it doesn't explicitly have an argument
4312+
// explicit call in an anchor expr, it doesn't explicitly have an argument
43134313
// info, so we just fake one for this situation.
43144314
if (locator->findLast<LocatorPathElt::ImplicitCallOfCallableValue>())
43154315
return ConstraintSystem::ArgumentInfo();

0 commit comments

Comments
 (0)