Skip to content

Commit 790773b

Browse files
authored
Merge pull request #8043 from slavapestov/fix-constructor-lookup-circularity
Sema: Fix crash if we try to look up constructors while validating a constructor
2 parents 5dd16fd + 068f3a1 commit 790773b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7915,6 +7915,19 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
79157915
return paramTy->getCanonicalType();
79167916
};
79177917

7918+
// Bail out if we're validating one of our constructors already; we'll
7919+
// revisit the issue later.
7920+
bool alreadyValidatingCtor = false;
7921+
for (auto member : decl->getMembers()) {
7922+
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
7923+
validateDecl(ctor);
7924+
if (!ctor->hasValidSignature())
7925+
alreadyValidatingCtor = true;
7926+
}
7927+
}
7928+
if (alreadyValidatingCtor)
7929+
return;
7930+
79187931
// Check whether there is a user-declared constructor or an instance
79197932
// variable.
79207933
bool FoundMemberwiseInitializedProperty = false;
@@ -7926,8 +7939,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
79267939
llvm::SmallPtrSet<ConstructorDecl *, 4> overriddenInits;
79277940
for (auto member : decl->getMembers()) {
79287941
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
7929-
validateDecl(ctor);
7930-
79317942
if (ctor->isDesignatedInit())
79327943
FoundDesignatedInit = true;
79337944

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %target-swift-frontend %s -typecheck -o /dev/null
2+
3+
class FakeDictionary<KeyType, ValueType> : ExpressibleByDictionaryLiteral {
4+
convenience required init(dictionaryLiteral elements: (FakeDictionary.Key, FakeDictionary.Value)...) {
5+
self.init()
6+
}
7+
}

0 commit comments

Comments
 (0)