Skip to content

Commit 00b3ce1

Browse files
committed
AST: Fix crash when doing name lookup into class with circular inheritance
1 parent 559c0fd commit 00b3ce1

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/AST/ConformanceLookupTable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ void ConformanceLookupTable::updateLookupTable(NominalTypeDecl *nominal,
319319
return;
320320
llvm::SaveAndRestore<bool> visiting(VisitingSuperclass, true);
321321

322+
// Don't update our own lookup table if we inherit from ourselves.
323+
if (classDecl == superclassDecl)
324+
break;
325+
322326
// Resolve the conformances of the superclass.
323327
superclassDecl->prepareConformanceTable();
324328
superclassDecl->ConformanceTable->updateLookupTable(

test/decl/class/circular_inheritance.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// RUN: %FileCheck -check-prefix CHECK-DOT %s < %t.dot
77

88
// Check that we produced superclass type requests.
9-
// RUN: %{python} %utils/process-stats-dir.py --evaluate 'SuperclassTypeRequest == 16' %t/stats-dir
9+
// RUN: %{python} %utils/process-stats-dir.py --evaluate 'SuperclassTypeRequest == 17' %t/stats-dir
1010

1111
class Left
1212
: Right.Hand {
@@ -59,3 +59,19 @@ class Outer3
5959

6060
// CHECK-DOT: digraph Dependencies
6161
// CHECK-DOT: label="InheritedTypeRequest
62+
63+
protocol Initable {
64+
init()
65+
// expected-note@-1 {{protocol requires initializer 'init()' with type '()'; do you want to add a stub?}}
66+
}
67+
68+
protocol Shape : Circle {}
69+
70+
class Circle : Initable & Circle {}
71+
// expected-error@-1 {{'Circle' inherits from itself}}
72+
// expected-error@-2 {{type 'Circle' does not conform to protocol 'Initable'}}
73+
74+
func crash() {
75+
Circle()
76+
// expected-error@-1 {{'Circle' cannot be constructed because it has no accessible initializers}}
77+
}

validation-test/compiler_crashers/28833-foundintype-isexistentialtype.swift renamed to validation-test/compiler_crashers_fixed/28833-foundintype-isexistentialtype.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
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
protocol A:a{}class a:RangeReplaceableCollection
1111
& a
1212
func<a

0 commit comments

Comments
 (0)