Add trivial accessors to static properties (as well as instance properties).

This is a better fix for rdar://problem/19941580: by providing trivial
accessors for all static properties, we have them there for any other
type checking that might need them, including the Objective-C selector
checking from the radar.

Swift SVN r25730
This commit is contained in:
Doug Gregor
2015-03-04 00:30:46 +00:00
parent d4a743c357
commit 2edae8c57d
4 changed files with 19 additions and 7 deletions

View File

@@ -1813,7 +1813,7 @@ void swift::maybeAddMaterializeForSet(AbstractStorageDecl *storage,
}
void swift::maybeAddAccessorsToVariable(VarDecl *var, TypeChecker &TC) {
if (var->getGetter() || var->isStatic() || var->isBeingTypeChecked())
if (var->getGetter() || var->isBeingTypeChecked())
return;
// Lazy variables need accessors.

View File

@@ -2655,12 +2655,7 @@ public:
TC.diagnose(VD->getLoc(), diag::extension_stored_property);
VD->setInvalid();
VD->overwriteType(ErrorType::get(TC.Context));
} // Objective-C compatible class types with static stored properties
// can be accessed as Objective-C class methods but need accessors
// to do so.
else if (VD->isObjC() && VD->isStatic() && VD->hasStorage())
if (!VD->hasAccessorFunctions())
addTrivialAccessorsToStorage(VD, TC);
}
}
// Synthesize accessors for lazy, all checking already been performed.

View File

@@ -31,3 +31,14 @@ public class SuperB : NSObject {
public class SubB : SuperB {
public override init(bar: String) { super.init(bar: bar) }
}
// rdar://problem/19941580
public class Foo : NSObject, FooProto {
public static var staticEntityName: String = "yo"
public var entityName: String = "yo"
}
@objc public protocol FooProto {
static var staticEntityName: String { get }
var entityName: String { get }
}

View File

@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse -parse-as-library -primary-file %S/Inputs/objc_multi_file_2.swift %s -verify
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse -parse-as-library -primary-file %s %S/Inputs/objc_multi_file_2.swift -verify
// RUN: rm -rf %t && mkdir %t
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-module %S/Inputs/objc_multi_file_2.swift -DFAKE_UIIMAGE -o %t
@@ -36,3 +37,8 @@ class SubSubB2 : SubB {
// okay: doesn't conflict with hidden initializer
func initWithWibble(s: String) { }
}
// rdar://problem/19941580
func rdar19941580(foo: Foo) {
var fp: FooProto = foo
}