Skip to content

Commit fc83c6f

Browse files
committed
[Diagnostics] Ignore type mismatches related to synthesized arguments
The main issue is the absence of the argument itself. Resolves: rdar://90419017
1 parent 7f2bde2 commit fc83c6f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,6 +4826,27 @@ bool ConstraintSystem::repairFailures(
48264826
case ConstraintLocator::ApplyArgToParam: {
48274827
auto loc = getConstraintLocator(locator);
48284828

4829+
// If this type mismatch is associated with a synthesized argument,
4830+
// let's just ignore it because the main problem is the absence of
4831+
// the argument.
4832+
if (auto applyLoc = elt.getAs<LocatorPathElt::ApplyArgToParam>()) {
4833+
if (auto *argumentList = getArgumentList(loc)) {
4834+
// This is either synthesized argument or a default value.
4835+
if (applyLoc->getArgIdx() >= argumentList->size()) {
4836+
auto *calleeLoc = getCalleeLocator(loc);
4837+
auto overload = findSelectedOverloadFor(calleeLoc);
4838+
// If this cannot be a default value matching, let's ignore.
4839+
if (!(overload && overload->choice.isDecl()))
4840+
return true;
4841+
4842+
if (!getParameterList(overload->choice.getDecl())
4843+
->get(applyLoc->getParamIdx())
4844+
->getTypeOfDefaultExpr())
4845+
return true;
4846+
}
4847+
}
4848+
}
4849+
48294850
// Don't attempt to fix an argument being passed to a
48304851
// _OptionalNilComparisonType parameter. Such an overload should only take
48314852
// effect when a nil literal is used in valid code, and doesn't offer any
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
public enum APIError {
4+
case unknown
5+
case message
6+
}
7+
8+
struct NewItemResponse {}
9+
10+
protocol Publisher {
11+
associatedtype Output // expected-note {{protocol requires nested type 'Output'; do you want to add it?}}
12+
}
13+
14+
extension Publisher {
15+
func sink(receiveCompletion: @escaping ((Int) -> Void), receiveValue: @escaping ((Self.Output) -> Void)) { fatalError() }
16+
// expected-note@-1 {{'sink(receiveCompletion:receiveValue:)' declared here}}
17+
}
18+
19+
func fetchFile<T>(name: String) -> MyPublisher<T, APIError> {
20+
fatalError()
21+
}
22+
23+
struct ReplaceError<Upstream> : Publisher { // expected-error {{type 'ReplaceError<Upstream>' does not conform to protocol 'Publisher'}}
24+
typealias Output = Upstream.Output // expected-error {{'Output' is not a member type of type 'Upstream'}}
25+
typealias Failure = Never
26+
}
27+
28+
struct MyPublisher<Output, Failure> : Publisher {
29+
init<P>(_ publisher: P) { fatalError() }
30+
31+
func replaceError(with output: Self.Output) -> ReplaceError<Self> { fatalError() }
32+
}
33+
34+
public class Items {
35+
func test() {
36+
_ = fetchFile(name: "abc")
37+
.replaceError(with: NewItemResponse())
38+
.sink { [weak self] items in } // expected-error {{missing argument for parameter 'receiveValue' in call}}
39+
}
40+
}

0 commit comments

Comments
 (0)