Skip to content

Commit faea569

Browse files
committed
[move-only] Ban @objc enum being marked as move only.
rdar://106340608
1 parent b9800fd commit faea569

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6797,6 +6797,8 @@ ERROR(moveonly_cast,none,
67976797
"move-only types cannot be conditionally cast", ())
67986798
ERROR(moveonly_failable_init,none,
67996799
"move-only types cannot have failable initializers yet", ())
6800+
ERROR(moveonly_objc_enum_banned, none,
6801+
"@objc enums cannot be marked as move-only", ())
68006802

68016803
//------------------------------------------------------------------------------
68026804
// MARK: Type inference from default expressions

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25472547
}
25482548
}
25492549

2550+
// -----
2551+
// NonCopyableChecks
2552+
//
2553+
2554+
if (ED->isObjC() && ED->isMoveOnly()) {
2555+
ED->diagnose(diag::moveonly_objc_enum_banned);
2556+
}
25502557
// FIXME(kavon): see if these can be integrated into other parts of Sema
25512558
diagnoseCopyableTypeContainingMoveOnlyType(ED);
25522559
diagnoseIncompatibleProtocolsForMoveOnlyType(ED);

test/Sema/moveonly_objc_enum.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-move-only
2+
3+
// Validate that we can't mark an objc enum as move only.
4+
5+
@_moveOnly
6+
@objc enum Foo : Int { // expected-error {{@objc enums cannot be marked as move-only}}
7+
case X, Y, Z
8+
deinit {} // objc enums cannot have deinits
9+
}
10+
11+
@_moveOnly
12+
@objc enum Foo2 : Int { // expected-error {{@objc enums cannot be marked as move-only}}
13+
case X, Y, Z
14+
}
15+

0 commit comments

Comments
 (0)