mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Type checker] Don't try to infer @objc from unavailable requirements.
@objc inference was looking at unavailable requirements---for which we don't ever record witnesses---at a point when it is no longer possible to record such a witness. This is a targeted fix; we need to tackle the issue of unavailable and optional requirements more thoroughly. Fixes SR-3917 / rdar://problem/30474860.
This commit is contained in:
@@ -5697,7 +5697,10 @@ TypeChecker::findWitnessedObjCRequirements(const ValueDecl *witness,
|
||||
|
||||
// Skip types.
|
||||
if (isa<TypeDecl>(req)) continue;
|
||||
|
||||
|
||||
// Skip unavailable requirements.
|
||||
if (req->getAttrs().isUnavailable(Context)) continue;
|
||||
|
||||
// Dig out the conformance.
|
||||
if (!conformance.hasValue()) {
|
||||
SmallVector<ProtocolConformance *, 2> conformances;
|
||||
|
||||
6
test/ClangImporter/Inputs/ImplementProtoRenaming.swift
Normal file
6
test/ClangImporter/Inputs/ImplementProtoRenaming.swift
Normal file
@@ -0,0 +1,6 @@
|
||||
import Foundation
|
||||
import ProtoRenaming
|
||||
|
||||
open class MyGraphView : NSObject, GraphViewSource {
|
||||
open func doSomething(to view: GraphView) { }
|
||||
}
|
||||
8
test/ClangImporter/Inputs/custom-modules/ProtoRenaming.h
Normal file
8
test/ClangImporter/Inputs/custom-modules/ProtoRenaming.h
Normal file
@@ -0,0 +1,8 @@
|
||||
@interface GraphView
|
||||
|
||||
@end
|
||||
|
||||
@protocol GraphViewSource
|
||||
@optional
|
||||
- (void)doSomethingToGraphView:(nonnull GraphView *)view;
|
||||
@end
|
||||
@@ -108,6 +108,11 @@ module PredefinedMacros {
|
||||
export *
|
||||
}
|
||||
|
||||
module ProtoRenaming {
|
||||
header "ProtoRenaming.h"
|
||||
export *
|
||||
}
|
||||
|
||||
module ProtoWithInitializer {
|
||||
header "ProtoWithInitializer.h"
|
||||
export *
|
||||
|
||||
20
test/ClangImporter/objc_protocol_renaming.swift
Normal file
20
test/ClangImporter/objc_protocol_renaming.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
// RUN: rm -rf %t && mkdir -p %t
|
||||
|
||||
// FIXME: BEGIN -enable-source-import hackaround
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -emit-module -o %t %clang-importer-sdk-path/swift-modules/CoreGraphics.swift
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -emit-module -o %t %clang-importer-sdk-path/swift-modules/Foundation.swift
|
||||
// FIXME: END -enable-source-import hackaround
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %S/Inputs/custom-modules -I %t) -emit-module -o %t %S/Inputs/ImplementProtoRenaming.swift
|
||||
|
||||
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %S/Inputs/custom-modules -I %t) -typecheck %s -verify
|
||||
|
||||
// REQUIRES: objc_interop
|
||||
|
||||
import ProtoRenaming
|
||||
import ImplementProtoRenaming
|
||||
|
||||
// SR-3917: compiler crash when using an "old" name for an imported requirement
|
||||
class MyGraphViewSubclass : MyGraphView {
|
||||
func doSomethingToGraphView(_ view: GraphView) { } // expected-error{{method 'doSomethingToGraphView' with Objective-C selector 'doSomethingToGraphView:' conflicts with method 'doSomething(to:)' from superclass 'MyGraphView' with the same Objective-C selector}}
|
||||
}
|
||||
Reference in New Issue
Block a user