Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change an assertion to an ad-hoc circularity check #10065

Merged
merged 1 commit into from
Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/AST/LookupVisibleDecls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ static void lookupVisibleMemberDeclsImpl(
return;
}

llvm::SmallPtrSet<ClassDecl *, 8> Ancestors;
do {
NominalTypeDecl *CurNominal = BaseTy->getAnyNominal();
if (!CurNominal)
Expand All @@ -571,8 +572,13 @@ static void lookupVisibleMemberDeclsImpl(
auto *CurClass = dyn_cast<ClassDecl>(CurNominal);

if (CurClass && CurClass->hasSuperclass()) {
assert(BaseTy.getPointer() != CurClass->getSuperclass().getPointer() &&
"type is its own superclass");
// FIXME: This path is no substitute for an actual circularity check.
// The real fix is to check that the superclass doesn't introduce a
// circular reference before it's written into the AST.
if (Ancestors.count(CurClass)) {
break;
}

BaseTy = CurClass->getSuperclass();
Reason = getReasonForSuper(Reason);

Expand All @@ -588,6 +594,7 @@ static void lookupVisibleMemberDeclsImpl(
} else {
break;
}
Ancestors.insert(CurClass);
} while (1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -typecheck
// RUN: not %target-swift-frontend %s -typecheck
// REQUIRES: asserts
struct c{class A:A{}var f=A.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -typecheck
// RUN: not %target-swift-frontend %s -typecheck
// REQUIRES: asserts
struct B{let d=A.b}class A:A{let a=V