Skip to content

Don't implicitly add dynamic to stored properties #20602

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
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
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,9 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
}

void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
if (!D->getModuleContext()->isImplicitDynamicEnabled())
return;

// Add the attribute if the decl kind allows it and it is not an accessor
// decl. Accessor decls should always infer the var/subscript's attribute.
if (!DeclAttribute::canAttributeAppearOnDecl(DAK_Dynamic, D) ||
Expand All @@ -2464,6 +2467,10 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
return;

if (auto *VD = dyn_cast<VarDecl>(D)) {
// Don't turn stored into computed properties. This could conflict with
// exclusivity checking.
if (VD->hasStorage())
return;
// Don't add dynamic to local variables.
if (VD->getDeclContext()->isLocalContext())
return;
Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,7 @@ IsDynamicRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
return false;

// Add dynamic if -enable-implicit-dynamic was requested.
if (decl->getModuleContext()->isImplicitDynamicEnabled()) {
TypeChecker::addImplicitDynamicAttribute(decl);
}
TypeChecker::addImplicitDynamicAttribute(decl);

// If 'dynamic' was explicitly specified, check it.
if (decl->getAttrs().hasAttribute<DynamicAttr>()) {
Expand Down
4 changes: 2 additions & 2 deletions test/Interpreter/Inputs/dynamic_replacement_module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public enum PublicEnumeration<Q> {
}
}
#elseif MODULENODYNAMIC
public var public_global_var = "public_global_var"
public dynamic var public_global_var = "public_global_var"

public func public_global_func() -> String {
return "public_global_func"
Expand Down Expand Up @@ -101,7 +101,7 @@ public struct PublicStruct {
public func genericFunction<T>(_ t: T.Type) -> String {
return "public_struct_generic_func"
}
public var public_stored_property : String = "public_stored_property"
dynamic public var public_stored_property : String = "public_stored_property"

public subscript(_ x: Int) -> String {
get {
Expand Down