Skip to content

Commit 1bf82a4

Browse files
author
Karl Wagner
committed
Expand tailored protocol-in-protocol diagnostic to include protocol extensions
1 parent 86783f0 commit 1bf82a4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25232523
if (NTD->getASTContext().LangOpts.hasFeature(Feature::NestedProtocols)) {
25242524
// Protocols may only be nested in non-generic contexts.
25252525
if (NTD->getParent()->isGenericContext()) {
2526-
if (isa<ProtocolDecl>(NTD->getParent())) {
2526+
if (NTD->getParent()->getSelfProtocolDecl()) {
25272527
NTD->diagnose(diag::unsupported_nested_protocol_in_protocol, NTD->getName());
25282528
} else {
25292529
NTD->diagnose(diag::unsupported_nested_protocol_in_generic_context, NTD->getName());

test/decl/nested/protocol_experimental.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,26 @@ protocol OuterProtocol {
172172

173173
struct ConformsToOuterProtocol : OuterProtocol {
174174
typealias Hen = Int
175-
176175
func f() { let _ = InnerProtocol.self } // expected-error {{use of protocol 'OuterProtocol.InnerProtocol' as a type must be written 'any OuterProtocol.InnerProtocol'}}
177176
}
178177

178+
extension OuterProtocol {
179+
protocol DefinedInExtension {} // expected-error{{protocol 'DefinedInExtension' cannot be nested inside another protocol}}
180+
}
181+
182+
extension OuterProtocol {
183+
func f() {
184+
protocol Invalid_0 {} // expected-error{{protocol 'Invalid_0' cannot be nested inside a generic context}}
185+
186+
struct SomeType { // expected-error{{type 'SomeType' cannot be nested in generic function 'f()'}}
187+
protocol Invalid_1 {} // expected-error{{protocol 'Invalid_1' cannot be nested inside a generic context}}
188+
}
189+
}
190+
func g<T>(_: T) {
191+
protocol Invalid_2 {} // expected-error{{protocol 'Invalid_2' cannot be nested inside a generic context}}
192+
}
193+
}
194+
179195
// 'InnerProtocol' does not inherit the generic parameters of
180196
// 'OtherGenericClass', so the occurrence of 'OtherGenericClass'
181197
// in 'InnerProtocol' is not "in context" with implicitly

0 commit comments

Comments
 (0)