Skip to content

Commit a52ad69

Browse files
committed
Sema: Avoid validateDecl() recursion through the 'unsupported existential' check
When type-checking decls, we would ensure they don't reference existential types formed from protocols with associated types or 'Self' requirements. However this check was done in both 'stage 1' and 'stage 2', which meant it would be called recursively from validateDecl(). Fix this by performing the check only once at the end of type checking a source file.
1 parent 0586bc6 commit a52ad69

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,8 +3495,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
34953495
}
34963496
}
34973497

3498-
if ((IsSecondPass && !IsFirstPass) ||
3499-
decl->getDeclContext()->getAsProtocolOrProtocolExtensionContext()) {
3498+
if (IsSecondPass && !IsFirstPass) {
35003499
TC.checkUnsupportedProtocolType(decl);
35013500
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
35023501
TC.checkDeclCircularity(nominal);
@@ -4284,8 +4283,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
42844283

42854284
if (IsSecondPass) {
42864285
checkAccessibility(TC, PD);
4287-
for (auto member : PD->getMembers())
4286+
for (auto member : PD->getMembers()) {
4287+
TC.checkUnsupportedProtocolType(member);
42884288
checkAccessibility(TC, member);
4289+
}
42894290
TC.checkInheritanceClause(PD);
42904291
return;
42914292
}
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
extension A{init(){}typealias e:A{}}protocol A{init(){}typealias e

validation-test/compiler_crashers/28489-this-genericenv-already-have-generic-context.swift renamed to validation-test/compiler_crashers_fixed/28489-this-genericenv-already-have-generic-context.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
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
// REQUIRES: asserts
1010
guard{protocol a{init()typealias e=a{}typealias e

0 commit comments

Comments
 (0)