Skip to content
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
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,9 @@ WARNING(access_control_non_objc_open_member,none,

ERROR(invalid_decl_attribute,none,
"'%0' attribute cannot be applied to this declaration", (DeclAttribute))
ERROR(attr_invalid_on_decl_kind,none,
"'%0' attribute cannot be applied to %1 declarations",
(DeclAttribute, DescriptiveDeclKind))
ERROR(invalid_decl_modifier,none,
"%0 modifier cannot be applied to this declaration", (DeclAttribute))
ERROR(attribute_does_not_apply_to_type,none,
Expand Down
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3626,6 +3626,12 @@ void AttributeChecker::checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs) {
}
}

if (isa<DestructorDecl>(D) || isa<ConstructorDecl>(D)) {
diagnoseAndRemoveAttr(Attr, diag::attr_invalid_on_decl_kind, Attr,
D->getDescriptiveKind());
continue;
}

auto AtLoc = Attr->AtLoc;
auto Platform = Attr->Platform;

Expand Down
10 changes: 10 additions & 0 deletions test/attr/attr_backDeploy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ extension TopLevelProtocol {
@_backDeploy(before: macOS 12.0) // expected-error {{'@_backDeploy' attribute cannot be applied to this declaration}}
public class CannotBackDeployClass {}

public final class CannotBackDeployClassInitDeinit {
@available(macOS 11.0, *)
@_backDeploy(before: macOS 12.0) // expected-error {{'@_backDeploy' attribute cannot be applied to initializer declarations}}
public init() {}

@available(macOS 11.0, *)
@_backDeploy(before: macOS 12.0) // expected-error {{'@_backDeploy' attribute cannot be applied to deinitializer declarations}}
deinit {}
}

@_backDeploy(before: macOS 12.0) // expected-error {{'@_backDeploy' attribute cannot be applied to this declaration}}
public struct CannotBackDeployStruct {
@_backDeploy(before: macOS 12.0) // expected-error {{'@_backDeploy' must not be used on stored properties}}
Expand Down