Skip to content

Commit ef08b1b

Browse files
committed
---
yaml --- r: 347643 b: refs/heads/master c: 1ce055f h: refs/heads/master i: 347641: 6cb4d26 347639: 53fbb18
1 parent bc318c5 commit ef08b1b

File tree

5 files changed

+64
-26
lines changed

5 files changed

+64
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: aa7888f5f8447d45fe425c717b451a74e06206c2
2+
refs/heads/master: 1ce055fbbf2c2ea474fa4cdeb70045affa241e4a
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/lib/Sema/CSDiagnostics.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,17 @@ bool MissingCallFailure::diagnoseAsError() {
15891589
}
15901590
}
15911591

1592+
if (auto *AE = dyn_cast<AssignExpr>(baseExpr)) {
1593+
auto *srcExpr = AE->getSrc();
1594+
if (auto *fnType = getType(srcExpr)->getAs<FunctionType>()) {
1595+
emitDiagnostic(srcExpr->getLoc(), diag::missing_nullary_call,
1596+
fnType->getResult())
1597+
.highlight(srcExpr->getSourceRange())
1598+
.fixItInsertAfter(srcExpr->getEndLoc(), "()");
1599+
return true;
1600+
}
1601+
}
1602+
15921603
emitDiagnostic(baseExpr->getLoc(), diag::did_not_call_function_value)
15931604
.fixItInsertAfter(insertLoc, "()");
15941605
return true;

trunk/lib/Sema/CSSimplify.cpp

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,24 +2006,44 @@ static ConstraintFix *fixRequirementFailure(ConstraintSystem &cs, Type type1,
20062006
/// Attempt to repair typing failures and record fixes if needed.
20072007
/// \return true if at least some of the failures has been repaired
20082008
/// successfully, which allows type matcher to continue.
2009-
static bool
2010-
repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
2011-
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
2012-
ConstraintLocatorBuilder locator) {
2009+
bool ConstraintSystem::repairFailures(
2010+
Type lhs, Type rhs, SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
2011+
ConstraintLocatorBuilder locator) {
20132012
SmallVector<LocatorPathElt, 4> path;
20142013
auto *anchor = locator.getLocatorParts(path);
20152014

20162015
if (path.empty()) {
2016+
if (!anchor)
2017+
return false;
2018+
20172019
// If method reference forms a value type of the key path,
20182020
// there is going to be a constraint to match result of the
20192021
// member lookup to the generic parameter `V` of *KeyPath<R, V>
20202022
// type associated with key path expression, which we need to
20212023
// fix-up here.
2022-
if (anchor && isa<KeyPathExpr>(anchor)) {
2024+
if (isa<KeyPathExpr>(anchor)) {
20232025
auto *fnType = lhs->getAs<FunctionType>();
20242026
if (fnType && fnType->getResult()->isEqual(rhs))
20252027
return true;
20262028
}
2029+
2030+
if (isa<AssignExpr>(anchor)) {
2031+
if (auto *fnType = lhs->getAs<FunctionType>()) {
2032+
// If left-hand side is a function type but right-hand
2033+
// side isn't, let's check it would be possible to fix
2034+
// this by forming an explicit call.
2035+
if (!rhs->is<FunctionType>() && !rhs->isVoid() &&
2036+
fnType->getNumParams() == 0 &&
2037+
matchTypes(fnType->getResult(), rhs, ConstraintKind::Conversion,
2038+
TypeMatchFlags::TMF_ApplyingFix, locator)
2039+
.isSuccess()) {
2040+
conversionsOrFixes.push_back(
2041+
InsertExplicitCall::create(*this, getConstraintLocator(locator)));
2042+
return true;
2043+
}
2044+
}
2045+
}
2046+
20272047
return false;
20282048
}
20292049

@@ -2033,14 +2053,14 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20332053
case ConstraintLocator::ApplyArgToParam: {
20342054
if (lhs->getOptionalObjectType() && !rhs->getOptionalObjectType()) {
20352055
conversionsOrFixes.push_back(
2036-
ForceOptional::create(cs, lhs, lhs->getOptionalObjectType(),
2037-
cs.getConstraintLocator(locator)));
2056+
ForceOptional::create(*this, lhs, lhs->getOptionalObjectType(),
2057+
getConstraintLocator(locator)));
20382058
}
20392059
break;
20402060
}
20412061

20422062
case ConstraintLocator::FunctionArgument: {
2043-
auto *argLoc = cs.getConstraintLocator(
2063+
auto *argLoc = getConstraintLocator(
20442064
locator.withPathElement(LocatorPathElt::getSynthesizedArgument(0)));
20452065

20462066
// Let's drop the last element which points to a single argument
@@ -2051,7 +2071,7 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20512071
path.back().getKind() == ConstraintLocator::ContextualType))
20522072
return false;
20532073

2054-
auto arg = llvm::find_if(cs.getTypeVariables(),
2074+
auto arg = llvm::find_if(getTypeVariables(),
20552075
[&argLoc](const TypeVariableType *typeVar) {
20562076
return typeVar->getImpl().getLocator() == argLoc;
20572077
});
@@ -2068,27 +2088,27 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20682088
//
20692089
// But if `T.Element` didn't get resolved to `Void` we'd like
20702090
// to diagnose this as a missing argument which can't be ignored.
2071-
if (arg != cs.getTypeVariables().end()) {
2091+
if (arg != getTypeVariables().end()) {
20722092
auto fnType = FunctionType::get({FunctionType::Param(lhs)},
2073-
cs.getASTContext().TheEmptyTupleType);
2093+
getASTContext().TheEmptyTupleType);
20742094
conversionsOrFixes.push_back(AddMissingArguments::create(
2075-
cs, fnType, {FunctionType::Param(*arg)},
2076-
cs.getConstraintLocator(anchor, path,
2077-
/*summaryFlags=*/0)));
2095+
*this, fnType, {FunctionType::Param(*arg)},
2096+
getConstraintLocator(anchor, path,
2097+
/*summaryFlags=*/0)));
20782098
}
20792099
break;
20802100
}
20812101

20822102
case ConstraintLocator::TypeParameterRequirement:
20832103
case ConstraintLocator::ConditionalRequirement: {
2084-
if (auto *fix = fixRequirementFailure(cs, lhs, rhs, anchor, path))
2104+
if (auto *fix = fixRequirementFailure(*this, lhs, rhs, anchor, path))
20852105
conversionsOrFixes.push_back(fix);
20862106
break;
20872107
}
20882108

20892109
case ConstraintLocator::ClosureResult: {
2090-
auto *fix = ContextualMismatch::create(cs, lhs, rhs,
2091-
cs.getConstraintLocator(locator));
2110+
auto *fix = ContextualMismatch::create(*this, lhs, rhs,
2111+
getConstraintLocator(locator));
20922112
conversionsOrFixes.push_back(fix);
20932113
break;
20942114
}
@@ -2098,14 +2118,14 @@ repairFailures(ConstraintSystem &cs, Type lhs, Type rhs,
20982118
// between them are mutability and/or root, value type mismatch.
20992119
if (isKnownKeyPathType(lhs) && isKnownKeyPathType(rhs)) {
21002120
auto *fix = KeyPathContextualMismatch::create(
2101-
cs, lhs, rhs, cs.getConstraintLocator(locator));
2121+
*this, lhs, rhs, getConstraintLocator(locator));
21022122
conversionsOrFixes.push_back(fix);
21032123
}
21042124

21052125
if (lhs->is<FunctionType>() && !rhs->is<AnyFunctionType>() &&
21062126
isa<ClosureExpr>(anchor)) {
2107-
auto *fix = ContextualMismatch::create(cs, lhs, rhs,
2108-
cs.getConstraintLocator(locator));
2127+
auto *fix = ContextualMismatch::create(*this, lhs, rhs,
2128+
getConstraintLocator(locator));
21092129
conversionsOrFixes.push_back(fix);
21102130
}
21112131
break;
@@ -2927,7 +2947,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
29272947

29282948
// Attempt to repair any failures identifiable at this point.
29292949
if (attemptFixes) {
2930-
if (repairFailures(*this, type1, type2, conversionsOrFixes, locator)) {
2950+
if (repairFailures(type1, type2, conversionsOrFixes, locator)) {
29312951
if (conversionsOrFixes.empty())
29322952
return getTypeMatchSuccess();
29332953
}
@@ -6476,6 +6496,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
64766496
return result;
64776497
}
64786498

6499+
case FixKind::InsertCall:
64796500
case FixKind::SkipSameTypeRequirement:
64806501
case FixKind::SkipSuperclassRequirement:
64816502
case FixKind::ContextualMismatch:
@@ -6484,7 +6505,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
64846505
}
64856506

64866507
case FixKind::UseSubscriptOperator:
6487-
case FixKind::InsertCall:
64886508
case FixKind::ExplicitlyEscaping:
64896509
case FixKind::CoerceToCheckedCast:
64906510
case FixKind::RelabelArguments:

trunk/lib/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,13 @@ class ConstraintSystem {
26242624
TypeMatchResult(SolutionKind result) : Kind(result) {}
26252625
};
26262626

2627+
/// Attempt to repair typing failures and record fixes if needed.
2628+
/// \return true if at least some of the failures has been repaired
2629+
/// successfully, which allows type matcher to continue.
2630+
bool repairFailures(Type lhs, Type rhs,
2631+
SmallVectorImpl<RestrictionOrFix> &conversionsOrFixes,
2632+
ConstraintLocatorBuilder locator);
2633+
26272634
/// Subroutine of \c matchTypes(), which matches up two tuple types.
26282635
///
26292636
/// \returns the result of performing the tuple-to-tuple conversion.

trunk/test/Constraints/fixes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func f4() -> B { }
1414
func f5(_ a: A) { }
1515
func f6(_ a: A, _: Int) { }
1616

17-
func createB() -> B { } // expected-note {{found this candidate}}
18-
func createB(_ i: Int) -> B { } // expected-note {{found this candidate}}
17+
func createB() -> B { }
18+
func createB(_ i: Int) -> B { }
1919

2020
func f7(_ a: A, _: @escaping () -> Int) -> B { }
2121
func f7(_ a: A, _: Int) -> Int { }
@@ -37,7 +37,7 @@ func forgotCall() {
3737
f6(f4, f2) // expected-error{{function produces expected type 'B'; did you mean to call it with '()'?}}{{8-8=()}}
3838

3939
// With overloading: only one succeeds.
40-
a = createB // expected-error{{ambiguous reference to member 'createB()'}}
40+
a = createB // expected-error{{function produces expected type 'B'; did you mean to call it with '()'?}}
4141

4242
// With overloading, pick the fewest number of fixes.
4343
var b = f7(f4, f1) // expected-error{{function produces expected type 'B'; did you mean to call it with '()'?}}

0 commit comments

Comments
 (0)