Skip to content

Commit 701392f

Browse files
committed
[NFC] Swap the order of checks in redeclaration checking
An nth order effect of computing isInvalid() is that we can potentially wind up type checking during redeclaration checking. This wouldn't normally be a problem, but under the current validation order it's more likely that the DeclChecker has already fired before we run redeclaration checking. If we move to any other validation order, the request wins. For VarDecl, that means the PatternBindingInitializerRequest fires and we type check with the pattern binding as the decl context. Under the previous scheme, we would visit the accessor decl and use that as the decl context. Here's the rub: The request case records a cascading dependency edge while the DeclChecker case records a private edge. This means the frontend can wind up emitting two different reference dependency sets for the same primaries as in NameBinding/reference-dependencies-consistency.swift Fix this by sinking the interface type computation after the access control check which, thankfully, does not depend on the interface type.
1 parent cd3ada5 commit 701392f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,6 @@ static void checkRedeclaration(ASTContext &ctx, ValueDecl *current) {
736736
if (!conflicting(currentSig, otherSig))
737737
continue;
738738

739-
// Skip invalid declarations.
740-
if (other->isInvalid())
741-
continue;
742-
743739
// Skip declarations in other files.
744740
// In practice, this means we will warn on a private declaration that
745741
// shadows a non-private one, but only in the file where the shadowing
@@ -748,6 +744,10 @@ static void checkRedeclaration(ASTContext &ctx, ValueDecl *current) {
748744
if (!other->isAccessibleFrom(currentDC))
749745
continue;
750746

747+
// Skip invalid declarations.
748+
if (other->isInvalid())
749+
continue;
750+
751751
// Thwart attempts to override the same declaration more than once.
752752
const auto *currentOverride = current->getOverriddenDecl();
753753
const auto *otherOverride = other->getOverriddenDecl();

0 commit comments

Comments
 (0)