mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Sema] Infer @objc and Objective-C name from conformance to a protocol.
When a particular method/initializer/property/subscript is used to satisfied a requirement in an @objc protocol, infer both the presence of @objc and the @objc name so that it matches the requirement. This eliminates the need to explicitly specify @objc and @objc(foo:bar:) in most cases. Note that we already did this for overrides, so it's a generalization of that behavior. Note that we keep this inference somewhat local, checking only those protocols that the enclosing context conforms to, to limit spooky-action-at-a-distance inference. It's possible that we could lift this restriction later. Fixes rdar://problem/24049773.
This commit is contained in:
@@ -741,12 +741,14 @@ void swift::addTrivialAccessorsToStorage(AbstractStorageDecl *storage,
|
||||
|
||||
// Create the getter.
|
||||
auto *getter = createGetterPrototype(storage, TC);
|
||||
if (storage->hasAccessorFunctions()) return;
|
||||
|
||||
// Create the setter.
|
||||
FuncDecl *setter = nullptr;
|
||||
ParamDecl *setterValueParam = nullptr;
|
||||
if (doesStorageNeedSetter(storage)) {
|
||||
setter = createSetterPrototype(storage, setterValueParam, TC);
|
||||
if (storage->hasAccessorFunctions()) return;
|
||||
}
|
||||
|
||||
// Okay, we have both the getter and setter. Set them in VD.
|
||||
@@ -964,10 +966,12 @@ static void convertNSManagedStoredVarToComputed(VarDecl *VD, TypeChecker &TC) {
|
||||
|
||||
// Create the getter.
|
||||
auto *Get = createGetterPrototype(VD, TC);
|
||||
if (VD->hasAccessorFunctions()) return;
|
||||
|
||||
// Create the setter.
|
||||
ParamDecl *SetValueDecl = nullptr;
|
||||
auto *Set = createSetterPrototype(VD, SetValueDecl, TC);
|
||||
if (VD->hasAccessorFunctions()) return;
|
||||
|
||||
// Okay, we have both the getter and setter. Set them in VD.
|
||||
VD->makeComputed(VD->getLoc(), Get, Set, nullptr, VD->getLoc());
|
||||
|
||||
Reference in New Issue
Block a user