Skip to content

[5.9] Sema: Skip storage diagnostic for @exclusivity in swiftinterfaces #65041

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
27 changes: 16 additions & 11 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2962,22 +2962,27 @@ void AttributeChecker::visitOptimizeAttr(OptimizeAttr *attr) {

void AttributeChecker::visitExclusivityAttr(ExclusivityAttr *attr) {
if (auto *varDecl = dyn_cast<VarDecl>(D)) {
if (!varDecl->hasStorage()) {
diagnose(attr->getLocation(), diag::exclusivity_on_computed_property);
attr->setInvalid();
return;
auto *DC = D->getDeclContext();
auto *parentSF = DC->getParentSourceFile();

if (parentSF && parentSF->Kind != SourceFileKind::Interface) {
if (!varDecl->hasStorage()) {
diagnose(attr->getLocation(), diag::exclusivity_on_computed_property);
attr->setInvalid();
return;
}
}
if (isa<ClassDecl>(varDecl->getDeclContext()))

if (isa<ClassDecl>(DC))
return;
if (varDecl->getDeclContext()->isTypeContext() && !varDecl->isInstanceMember())

if (DC->isTypeContext() && !varDecl->isInstanceMember())
return;
if (varDecl->getDeclContext()->isModuleScopeContext())

if (DC->isModuleScopeContext())
return;
}
diagnose(attr->getLocation(), diag::exclusivity_on_wrong_decl);
diagnoseAndRemoveAttr(attr, diag::exclusivity_on_wrong_decl);
attr->setInvalid();
}

Expand Down
43 changes: 43 additions & 0 deletions test/ModuleInterface/exclusivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name exclusivity
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name exclusivity
// RUN: %FileCheck %s < %t.swiftinterface

// CHECK: @exclusivity(checked) public var checkedGlobalVar: Swift.Int
@exclusivity(checked)
public var checkedGlobalVar = 1

// CHECK: @exclusivity(unchecked) public var uncheckedGlobalVar: Swift.Int
@exclusivity(unchecked)
public var uncheckedGlobalVar = 1

// CHECK-LABEL: public struct Struct
public struct Struct {
// CHECK: @exclusivity(unchecked) public static var uncheckedStaticVar: Swift.Int
@exclusivity(unchecked)
public static var uncheckedStaticVar: Int = 27

// CHECK: @exclusivity(checked) public static var checkedStaticVar: Swift.Int
@exclusivity(checked)
public static var checkedStaticVar: Int = 27
}

// CHECK-LABEL: public class Class
public class Class {
// CHECK: @exclusivity(unchecked) public var uncheckedInstanceVar: Swift.Int
@exclusivity(unchecked)
public var uncheckedInstanceVar: Int = 27

// CHECK: @exclusivity(checked) public var checkedInstanceVar: Swift.Int
@exclusivity(checked)
public var checkedInstanceVar: Int = 27

// CHECK: @exclusivity(unchecked) public var uncheckedPrivateSetInstanceVar: Swift.Int {
// CHECK-NEXT: get
// CHECK-NEXT: }
@exclusivity(unchecked)
public private(set) var uncheckedPrivateSetInstanceVar: Int = 27

// CHECK: @exclusivity(unchecked) public static var uncheckedStaticVar: Swift.Int
@exclusivity(unchecked)
public static var uncheckedStaticVar: Int = 27
}
6 changes: 3 additions & 3 deletions test/SILGen/exclusivityattr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public func getUncheckedVar() -> Int {
return globalUncheckedVar
}

public class ExclusivityAttrStruct {
public struct ExclusivityAttrStruct {

// CHECK-LABEL: sil {{.*}}@$s4test21ExclusivityAttrStructC9staticVarSivsZ
// CHECK-LABEL: sil {{.*}}@$s4test21ExclusivityAttrStructV9staticVarSivsZ
// CHECK-ON: begin_access [modify] [unsafe]
// CHECK: } // end sil function '$s4test21ExclusivityAttrStructC9staticVarSivsZ'
// CHECK: } // end sil function '$s4test21ExclusivityAttrStructV9staticVarSivsZ'
@exclusivity(unchecked)
public static var staticVar: Int = 27
}
Expand Down