Skip to content

Commit 8248020

Browse files
committed
[Sema] Require availability for inits and subscripts in extensions
1 parent 0d0dd53 commit 8248020

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
16851685

16861686
checkAccessControl(SD);
16871687

1688+
checkExplicitAvailability(SD);
1689+
16881690
if (!checkOverrides(SD)) {
16891691
// If a subscript has an override attribute but does not override
16901692
// anything, complain.
@@ -2644,6 +2646,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26442646

26452647
checkAccessControl(CD);
26462648

2649+
checkExplicitAvailability(CD);
2650+
26472651
if (requiresDefinition(CD) && !CD->hasBody()) {
26482652
// Complain if we should have a body.
26492653
CD->diagnose(diag::missing_initializer_def);

test/attr/require_explicit_availability.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,30 @@ public var computedOk1: S {
137137
get { return S() }
138138
set { }
139139
}
140+
141+
public class SomeClass { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}}
142+
public init () {}
143+
144+
public subscript(index: String) -> Int {
145+
get { return 42; }
146+
set(newValue) { }
147+
}
148+
}
149+
150+
extension SomeClass { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{1-1=@available(macOS 10.10, *)\n}}
151+
public convenience init(s : S) {} // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{3-3=@available(macOS 10.10, *)\n }}
152+
153+
@available(macOS 10.10, *)
154+
public convenience init(s : SomeClass) {}
155+
156+
public subscript(index: Int) -> Int { // expected-warning {{public declarations should have an availability attribute when building with -require-explicit-availability}} {{3-3=@available(macOS 10.10, *)\n }}
157+
get { return 42; }
158+
set(newValue) { }
159+
}
160+
161+
@available(macOS 10.10, *)
162+
public subscript(index: S) -> Int {
163+
get { return 42; }
164+
set(newValue) { }
165+
}
166+
}

0 commit comments

Comments
 (0)