Skip to content

Commit 583d617

Browse files
authored
Merge pull request #36786 from xedin/partial-note-crash-objc-optionals
[Diagnostics] Fix crash while trying to print candidates for a option…
2 parents c7a8b56 + a16d557 commit 583d617

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3706,7 +3706,11 @@ static bool diagnoseAmbiguity(
37063706
})) {
37073707
// All fixes have to do with arguments, so let's show the parameter
37083708
// lists.
3709-
auto *fn = type->getAs<AnyFunctionType>();
3709+
//
3710+
// It's possible that function type is wrapped in an optional
3711+
// if it's from `@objc optional` method, so we need to ignore that.
3712+
auto *fn =
3713+
type->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
37103714
assert(fn);
37113715

37123716
if (fn->getNumParams() == 1) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
@objc protocol P {
7+
@objc optional static func test(a: UnsafePointer<Int>, _: Int)
8+
// expected-note@-1 {{candidate has partially matching parameter list (a: UnsafePointer<Int>, Int)}}
9+
@objc optional static func test(b: [Int], _: Int)
10+
// expected-note@-1 {{candidate has partially matching parameter list (b: [Int], Int)}}
11+
}
12+
13+
@objc class S : NSObject, P {
14+
static func test(a: UnsafePointer<Int>, _: Int) {}
15+
static func test(b: [Int], _: Int) {}
16+
}
17+
18+
func test(s: P.Type, v: Int) {
19+
_ = s.test!(c: v, 0) // expected-error {{no exact matches in call to static method 'test'}}
20+
}

0 commit comments

Comments
 (0)