File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
validation-test/Sema/type_checker_crashers_fixed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -4826,6 +4826,27 @@ bool ConstraintSystem::repairFailures(
4826
4826
case ConstraintLocator::ApplyArgToParam: {
4827
4827
auto loc = getConstraintLocator(locator);
4828
4828
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
+
4829
4850
// Don't attempt to fix an argument being passed to a
4830
4851
// _OptionalNilComparisonType parameter. Such an overload should only take
4831
4852
// effect when a nil literal is used in valid code, and doesn't offer any
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments