Skip to content

Commit 4c0d148

Browse files
committed
Sema: Don't add implicit constructors when checking inheritance clause
This leads to some bad recursion through validateDecl(), even when called from the ITC. We already had machinery to add implicit constructors later, it just had to be extended to do it for the superclass as well.
1 parent 9beabec commit 4c0d148

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,6 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
560560
// Set the superclass.
561561
if (auto classDecl = dyn_cast<ClassDecl>(decl)) {
562562
classDecl->setSuperclass(superclassTy);
563-
if (superclassTy)
564-
resolveImplicitConstructors(superclassTy->getClassOrBoundGenericClass());
565563
} else if (auto enumDecl = dyn_cast<EnumDecl>(decl)) {
566564
enumDecl->setRawType(superclassTy);
567565
} else {
@@ -7859,10 +7857,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
78597857
// for all of the superclass's designated initializers.
78607858
// FIXME: Currently skipping generic classes.
78617859
auto classDecl = cast<ClassDecl>(decl);
7862-
assert(!classDecl->hasSuperclass() ||
7863-
classDecl->getSuperclass()->getAnyNominal()->isInvalid() ||
7864-
classDecl->getSuperclass()->getAnyNominal()
7865-
->addedImplicitInitializers());
78667860
if (classDecl->hasSuperclass()) {
78677861
bool canInheritInitializers = !FoundDesignatedInit;
78687862

@@ -7874,6 +7868,11 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
78747868
}
78757869

78767870
auto superclassTy = classDecl->getSuperclass();
7871+
auto *superclassDecl = superclassTy->getClassOrBoundGenericClass();
7872+
assert(superclassDecl && "Superclass of class is not a class?");
7873+
if (!superclassDecl->addedImplicitInitializers())
7874+
addImplicitConstructors(superclassDecl);
7875+
78777876
auto ctors = lookupConstructors(classDecl, superclassTy,
78787877
NameLookupFlags::IgnoreAccessibility);
78797878

test/SILGen/accessibility_vtables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class InternalSub : InternalBase {
3838

3939
// CHECK-LABEL: sil_vtable InternalSub {
4040
// CHECK-NEXT: #InternalBase.method!1: _TFC21accessibility_vtables12InternalBaseP{{[0-9]+}}[[DISCRIMINATOR:_.+]]6method
41-
// CHECK-NEXT: #InternalBase.init!initializer.1: _TFC21accessibility_vtables11InternalSubc
4241
// CHECK-NEXT: #InternalBase.prop!getter.1: _TFC21accessibility_vtables11InternalSubg4propSi // accessibility_vtables.InternalSub.prop.getter : Swift.Int
4342
// CHECK-NEXT: #InternalBase.prop!setter.1: _TFC21accessibility_vtables12InternalBases4propSi // accessibility_vtables.InternalBase.prop.setter : Swift.Int
4443
// CHECK-NEXT: #InternalBase.prop!materializeForSet.1: _TFC21accessibility_vtables12InternalBasem4propSi // accessibility_vtables.InternalBase.prop.materializeForSet : Swift.Int
44+
// CHECK-NEXT: #InternalBase.init!initializer.1: _TFC21accessibility_vtables11InternalSubc
4545
// CHECK-NEXT: #InternalSub.method!1: _TFC21accessibility_vtables11InternalSub6method
4646
// CHECK-NEXT: #InternalSub.prop!setter.1: _TFC21accessibility_vtables11InternalSubs4propSi // accessibility_vtables.InternalSub.prop.setter : Swift.Int
4747
// CHECK-NEXT: #InternalSub.prop!materializeForSet.1: _TFC21accessibility_vtables11InternalSubm4propSi // accessibility_vtables.InternalSub.prop.materializeForSet : Swift.Int

test/SILGen/objc_attr_NSManaged.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ extension ProtoAdopter {
9999

100100
// The vtable should not contain any entry points for getters and setters.
101101
// CHECK-LABEL: sil_vtable SwiftGizmo {
102-
// CHECK-NEXT: #SwiftGizmo.modifyX!1: _TFC19objc_attr_NSManaged10SwiftGizmo7modifyX
103-
// CHECK-NEXT: #SwiftGizmo.testFunc!1: _TFC19objc_attr_NSManaged10SwiftGizmo8testFunc
104-
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10SwiftGizmoc
102+
// CHECK-NEXT: #SwiftGizmo.modifyX!1: _TFC19objc_attr_NSManaged10SwiftGizmo7modifyX
103+
// CHECK-NEXT: #SwiftGizmo.testFunc!1: _TFC19objc_attr_NSManaged10SwiftGizmo8testFunc
104+
// CHECK-NEXT: #SwiftGizmo.deinit!deallocator:
105+
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10SwiftGizmoc
105106
// CHECK-NEXT: #SwiftGizmo.init!initializer.1: _TFC19objc_attr_NSManaged10SwiftGizmoc
106-
// CHECK-NEXT: #SwiftGizmo.deinit!deallocator:
107107
// CHECK-NEXT: }
108108

109109
// CHECK-LABEL: sil_vtable FinalGizmo {

test/decl/class/circular_inheritance.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ protocol P : P {} // expected-error{{circular protocol inheritance P}}
1010
class Isomorphism : Automorphism { }
1111
class Automorphism : Automorphism { } // expected-error{{circular class inheritance Automorphism}}
1212

13-
let _ = A()
13+
// FIXME: Useless error
14+
let _ = A() // expected-error{{'A' cannot be constructed because it has no accessible initializers}}
1415

1516
// This should probably be made to work, but for now test that it produces a crappy
1617
// diagnostic instead of crashing

validation-test/compiler_crashers/28386-swift-typebase-getdesugaredtype.swift renamed to validation-test/compiler_crashers_fixed/28386-swift-typebase-getdesugaredtype.swift

Lines changed: 1 addition & 1 deletion
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-
// RUN: not --crash %target-swift-frontend %s -typecheck
8+
// RUN: not %target-swift-frontend %s -typecheck
99
struct A{init(){let:A
1010
class B:A
1111
class A:B{
Lines changed: 1 addition & 1 deletion
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-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
// REQUIRES: asserts
1010
protocol A{enum S{var f=e
1111
typealias f:B

0 commit comments

Comments
 (0)