Skip to content

Commit 51198e4

Browse files
Merge pull request #20602 from aschwaighofer/no_implicit_dynamic_stored_property
Don't implicitly add dynamic to stored properties
2 parents f9e6df3 + b255b8a commit 51198e4

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,9 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
24512451
}
24522452

24532453
void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
2454+
if (!D->getModuleContext()->isImplicitDynamicEnabled())
2455+
return;
2456+
24542457
// Add the attribute if the decl kind allows it and it is not an accessor
24552458
// decl. Accessor decls should always infer the var/subscript's attribute.
24562459
if (!DeclAttribute::canAttributeAppearOnDecl(DAK_Dynamic, D) ||
@@ -2464,6 +2467,10 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
24642467
return;
24652468

24662469
if (auto *VD = dyn_cast<VarDecl>(D)) {
2470+
// Don't turn stored into computed properties. This could conflict with
2471+
// exclusivity checking.
2472+
if (VD->hasStorage())
2473+
return;
24672474
// Don't add dynamic to local variables.
24682475
if (VD->getDeclContext()->isLocalContext())
24692476
return;

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,9 +1215,7 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
12151215
return false;
12161216

12171217
// Add dynamic if -enable-implicit-dynamic was requested.
1218-
if (decl->getModuleContext()->isImplicitDynamicEnabled()) {
1219-
TypeChecker::addImplicitDynamicAttribute(decl);
1220-
}
1218+
TypeChecker::addImplicitDynamicAttribute(decl);
12211219

12221220
// If 'dynamic' was explicitly specified, check it.
12231221
if (decl->getAttrs().hasAttribute<DynamicAttr>()) {

test/Interpreter/Inputs/dynamic_replacement_module.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public enum PublicEnumeration<Q> {
6666
}
6767
}
6868
#elseif MODULENODYNAMIC
69-
public var public_global_var = "public_global_var"
69+
public dynamic var public_global_var = "public_global_var"
7070

7171
public func public_global_func() -> String {
7272
return "public_global_func"
@@ -101,7 +101,7 @@ public struct PublicStruct {
101101
public func genericFunction<T>(_ t: T.Type) -> String {
102102
return "public_struct_generic_func"
103103
}
104-
public var public_stored_property : String = "public_stored_property"
104+
dynamic public var public_stored_property : String = "public_stored_property"
105105

106106
public subscript(_ x: Int) -> String {
107107
get {

0 commit comments

Comments
 (0)