Skip to content

[Diagnostics] Fix crash while trying to print candidates for a option… #36786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions test/Constraints/objc_optional_methods_diagnostics.swift
Original file line number Diff line number Diff line change
@@ -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'}}
}