Skip to content

Commit 3ae11e6

Browse files
committed
Sema: Fix a recusive validation crasher
1 parent ef86409 commit 3ae11e6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,6 +3723,13 @@ void TypeChecker::validateDecl(ValueDecl *D) {
37233723
return;
37243724
}
37253725

3726+
// Validating the parent may have triggered validation of this declaration,
3727+
// so just return if that was the case.
3728+
if (D->hasValidationStarted()) {
3729+
assert(D->hasValidSignature());
3730+
return;
3731+
}
3732+
37263733
if (Context.Stats)
37273734
Context.Stats->getFrontendCounters().NumDeclsValidated++;
37283735

test/decl/nested/protocol.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,13 @@ protocol SelfDotTest {
7979
class Class {}
8080
// expected-error@-1{{type 'Class' cannot be nested in protocol 'SelfDotTest'}}
8181
}
82+
83+
struct Outer {
84+
typealias E = NestedValidation.T
85+
protocol NestedValidation { // expected-error {{protocol 'NestedValidation' cannot be nested inside another declaration}}
86+
typealias T = A.B
87+
class A { // expected-error {{type 'A' cannot be nested in protocol 'NestedValidation'}}
88+
typealias B = Int
89+
}
90+
}
91+
}

validation-test/compiler_crashers/28797-declbits-beingvalidated-ibv.swift renamed to validation-test/compiler_crashers_fixed/28797-declbits-beingvalidated-ibv.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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-
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
{typealias e:P.a
1111
protocol P{typealias a=a.b:class a

0 commit comments

Comments
 (0)