Skip to content

Commit 6042784

Browse files
committed
Sema: Tweak re-declaration checking behavior to match old logic
The parser's own re-declaration checking for local declarations has slightly different behavior than Sema's re-declaration check. Whereas Sema rejects this: class C { let x = 123 func x() {} } The parser accepts this: func f() { let x = 123 func x() {} } With Sema's check now handling both cases, fudge the behavior to match the parser in the local case.
1 parent 2765df6 commit 6042784

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ CheckRedeclarationRequest::evaluate(Evaluator &eval, ValueDecl *current) const {
572572
if (currentDC->isTypeContext() != other->getDeclContext()->isTypeContext())
573573
continue;
574574

575+
// In local context, only consider exact name matches.
576+
if (currentDC->isLocalContext() &&
577+
current->getName() != other->getName())
578+
continue;
579+
575580
// Check whether the overload signatures conflict (ignoring the type for
576581
// now).
577582
auto otherSig = other->getOverloadSignature();

test/Sema/redeclaration-checking.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,9 @@ func stmtTest() {
9393
// expected-error@-2 {{invalid redeclaration of 'x'}}
9494
// expected-warning@-3 2{{never used}}
9595
// expected-warning@-4 {{unreachable}}
96+
}
97+
98+
func fullNameTest() {
99+
let x = 123 // expected-warning {{never used}}
100+
func x() {}
96101
}

0 commit comments

Comments
 (0)