Skip to content

Commit 1e25de1

Browse files
authored
Merge pull request swiftlang#71276 from hamishknight/type-var-decl
[CS] Don't walk into local decls in TypeVariableRefFinder
2 parents bc8efec + 8773521 commit 1e25de1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ class TypeVariableRefFinder : public ASTWalker {
178178
return Action::Continue(stmt);
179179
}
180180

181+
PreWalkAction walkToDeclPre(Decl *D) override {
182+
/// Decls get type-checked separately, except for PatternBindingDecls,
183+
/// whose initializers we want to walk into.
184+
return Action::VisitChildrenIf(isa<PatternBindingDecl>(D));
185+
}
186+
181187
private:
182188
DeclContext *currentClosureDC() const {
183189
return ClosureDCs.empty() ? nullptr : ClosureDCs.back();

test/Constraints/issue-71273.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/apple/swift/issues/71273
4+
5+
func bar<R>(_ fn: () -> R) {}
6+
7+
// Make sure we don't error here.
8+
func testLocalFn() {
9+
bar() {
10+
func foo() -> Int { return 0 }
11+
return ()
12+
}
13+
}
14+
15+
func testLocalBinding() {
16+
bar() {
17+
let _ = if .random() { return () } else { 0 }
18+
// expected-error@-1 {{cannot 'return' in 'if' when used as expression}}
19+
return ()
20+
}
21+
}

0 commit comments

Comments
 (0)