Skip to content

Commit aaa8b64

Browse files
committed
[SE-0316] Ban "class subscript" in actors, too
1 parent 110fbdd commit aaa8b64

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
@@ -2003,6 +2003,14 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
20032003
}
20042004
}
20052005

2006+
// Reject "class" methods on actors.
2007+
if (SD->getStaticSpelling() == StaticSpellingKind::KeywordClass &&
2008+
SD->getDeclContext()->getSelfClassDecl() &&
2009+
SD->getDeclContext()->getSelfClassDecl()->isActor()) {
2010+
SD->diagnose(diag::class_subscript_not_in_class, false)
2011+
.fixItReplace(SD->getStaticLoc(), "static");
2012+
}
2013+
20062014
// Now check all the accessors.
20072015
SD->visitEmittedAccessors([&](AccessorDecl *accessor) {
20082016
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)