[Diagnostics] Fix crash while trying to print candidates for a optional @objc method reference

This commit is contained in:
Pavel Yaskevich
2021-04-06 16:20:57 -07:00
parent 4de232ec57
commit a16d557fd0
2 changed files with 25 additions and 1 deletions

View File

@@ -3706,7 +3706,11 @@ static bool diagnoseAmbiguity(
})) {
// All fixes have to do with arguments, so let's show the parameter
// lists.
auto *fn = type->getAs<AnyFunctionType>();
//
// It's possible that function type is wrapped in an optional
// if it's from `@objc optional` method, so we need to ignore that.
auto *fn =
type->lookThroughAllOptionalTypes()->getAs<AnyFunctionType>();
assert(fn);
if (fn->getNumParams() == 1) {

View File

@@ -0,0 +1,20 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s
// REQUIRES: objc_interop
import Foundation
@objc protocol P {
@objc optional static func test(a: UnsafePointer<Int>, _: Int)
// expected-note@-1 {{candidate has partially matching parameter list (a: UnsafePointer<Int>, Int)}}
@objc optional static func test(b: [Int], _: Int)
// expected-note@-1 {{candidate has partially matching parameter list (b: [Int], Int)}}
}
@objc class S : NSObject, P {
static func test(a: UnsafePointer<Int>, _: Int) {}
static func test(b: [Int], _: Int) {}
}
func test(s: P.Type, v: Int) {
_ = s.test!(c: v, 0) // expected-error {{no exact matches in call to static method 'test'}}
}