Skip to content

Commit 102c001

Browse files
committed
[SE-0316] Ban "class subscript" in actors, too
1 parent 2bb94f8 commit 102c001

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,14 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
21072107
}
21082108
}
21092109

2110+
// Reject "class" methods on actors.
2111+
if (SD->getStaticSpelling() == StaticSpellingKind::KeywordClass &&
2112+
SD->getDeclContext()->getSelfClassDecl() &&
2113+
SD->getDeclContext()->getSelfClassDecl()->isActor()) {
2114+
SD->diagnose(diag::class_subscript_not_in_class, false)
2115+
.fixItReplace(SD->getStaticLoc(), "static");
2116+
}
2117+
21102118
// Now check all the accessors.
21112119
SD->visitEmittedAccessors([&](AccessorDecl *accessor) {
21122120
visit(accessor);

test/decl/class/actor/basic.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,7 @@ actor A2 {
4444
extension A2 {
4545
class func h2() { } // expected-error{{class methods are only allowed within classes; use 'static' to declare a static method}}
4646
static func i2() { } // okay
47+
48+
class subscript(i: Int) -> Int { i } // expected-error{{class subscripts are only allowed within classes; use 'static' to declare a static subscript}}
49+
static subscript(s: String) -> String { s }
4750
}

0 commit comments

Comments
 (0)