Skip to content

Commit c49a1d7

Browse files
committed
AST: Stricter DeclContext::getParentForLookup()
1 parent 9e1f60d commit c49a1d7

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

lib/AST/DeclContext.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ DeclContext *DeclContext::getParentForLookup() const {
445445
// outer types.
446446
return getModuleScopeContext();
447447
}
448+
if (isa<NominalTypeDecl>(this)) {
449+
// If we are inside a nominal type that is inside a protocol,
450+
// skip the protocol.
451+
if (isa<ProtocolDecl>(getParent()))
452+
return getModuleScopeContext();
453+
}
448454
return getParent();
449455
}
450456

test/decl/nested/protocol.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ protocol Racoon {
4040
associatedtype Stripes
4141
class Claw<T> { // expected-error{{type 'Claw' cannot be nested in protocol 'Racoon'}}
4242
func mangle(_ s: Stripes) {}
43+
// expected-error@-1 {{use of undeclared type 'Stripes'}}
4344
}
4445
struct Fang<T> { // expected-error{{type 'Fang' cannot be nested in protocol 'Racoon'}}
4546
func gnaw(_ s: Stripes) {}
47+
// expected-error@-1 {{use of undeclared type 'Stripes'}}
4648
}
4749
enum Fur { // expected-error{{type 'Fur' cannot be nested in protocol 'Racoon'}}
4850
case Stripes

validation-test/compiler_crashers/28753-conforms-equivclass-conformsto-end.swift renamed to validation-test/compiler_crashers_fixed/28753-conforms-equivclass-conformsto-end.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
protocol A:A{{}class a{let ca{a{

validation-test/compiler_crashers/28765-inprotocol-isrequirementsignaturecomputed-missing-signature.swift renamed to validation-test/compiler_crashers_fixed/28765-inprotocol-isrequirementsignaturecomputed-missing-signature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
protocol P{{}class a:A{}protocol A:P.a{typealias a{}func a:a

validation-test/compiler_crashers/28773-unreachable-executed-at-swift-lib-sema-cssimplify-cpp-4808.swift renamed to validation-test/compiler_crashers_fixed/28773-unreachable-executed-at-swift-lib-sema-cssimplify-cpp-4808.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
@objc protocol P{{}typealias a{}class a{let c=a{

0 commit comments

Comments
 (0)