Skip to content

Commit 8f4f37f

Browse files
[Sema] Fixes infinite recursion when inheriting from a member of the same type
1 parent a2cf18b commit 8f4f37f

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,25 @@ static Type resolveIdentTypeComponent(
11341134
diagnoseErrors, resolver,
11351135
unsatisfiedDependency);
11361136
if (!parentTy || parentTy->is<ErrorType>()) return parentTy;
1137-
1138-
// Resolve the nested type.
1137+
11391138
SourceRange parentRange(parentComps.front()->getIdLoc(),
11401139
parentComps.back()->getSourceRange().End);
1140+
1141+
// Don't resolve the nested type if the parent is equal to the decl context
1142+
// we are looking in.
1143+
auto selfTypeBase = DC->getSelfTypeInContext().getPointer();
1144+
if (DC->getAsClassOrClassExtensionContext() &&
1145+
selfTypeBase && selfTypeBase->isEqual(parentTy)) {
1146+
if (diagnoseErrors) {
1147+
TC.diagnose(parentComps.front()->getStartLoc(),
1148+
diag::circular_class_inheritance,
1149+
parentComps.front()->getIdentifier().str())
1150+
.fixItRemove(parentRange);
1151+
}
1152+
return ErrorType::get(TC.Context);
1153+
}
1154+
1155+
// Resolve the nested type.
11411156
return resolveNestedIdentTypeComponent(TC, DC, parentTy,
11421157
parentRange, comp,
11431158
options, diagnoseErrors,

validation-test/compiler_crashers/08008-swift-typechecker-typecheckexpression.swift renamed to validation-test/compiler_crashers_2_fixed/08008-swift-typechecker-typecheckexpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// ASAN Output: stack-overflow on address 0x7fffe2a98fd8 (pc 0x000001e12adb bp 0x7fffe2a992d0 sp 0x7fffe2a98f60 T0)
1010
class A:A.b{let b=Void{

validation-test/compiler_crashers/21765-vtable.swift renamed to validation-test/compiler_crashers_fixed/21765-vtable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// ASAN Output: stack-overflow on address 0x7ffe8def3f70 (pc 0x000001cf1268 bp 0x7ffe8def48f0 sp 0x7ffe8def3f00 T0)
1010
func b<T {
1111
class A : A.e {

validation-test/compiler_crashers/27939-vtable.swift renamed to validation-test/compiler_crashers_fixed/27939-vtable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// ASAN Output: stack-overflow on address 0x7ffdad0b1cd0 (pc 0x000001cf1268 bp 0x7ffdad0b2650 sp 0x7ffdad0b1c60 T0)
1010
func b<T {
1111
class A : A.e {

0 commit comments

Comments
 (0)