mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Diagnostics] Fix crash while trying to print candidates for a optional @objc method reference
This commit is contained in:
@@ -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) {
|
||||
|
||||
20
test/Constraints/objc_optional_methods_diagnostics.swift
Normal file
20
test/Constraints/objc_optional_methods_diagnostics.swift
Normal 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'}}
|
||||
}
|
||||
Reference in New Issue
Block a user