Skip to content

Commit 144395e

Browse files
committed
Fix top-level crash/missing diagnostic
This patch fixes the crash on assertion builds and the missing diagnostic on normal builds when operating on declarations in the top-level context.
1 parent fe309fc commit 144395e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,10 @@ static void lookupReplacedDecl(DeclNameRef replacedDeclName,
27332733
SmallVectorImpl<ValueDecl *> &results) {
27342734
auto *declCtxt = replacement->getDeclContext();
27352735

2736+
// Hop up to the FileUnit if we're in top-level code
2737+
if (auto *toplevel = dyn_cast<TopLevelCodeDecl>(declCtxt))
2738+
declCtxt = toplevel->getDeclContext();
2739+
27362740
// Look at the accessors' storage's context.
27372741
if (auto *accessor = dyn_cast<AccessorDecl>(replacement)) {
27382742
auto *storage = accessor->getStorage();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: concurrency
2+
3+
// RUN: %target-typecheck-verify-swift
4+
5+
if #available(macOS 12.0, *) {
6+
@available(*, renamed: "process(data:)")
7+
func process(data: [Int], completion: @escaping ([Int]) -> Void) { completion(data) }
8+
// expected-note@+1{{'process(data:)' declared here}}
9+
func process(data: [Int]) async -> [Int] { return data }
10+
11+
func asyncFunc(data: [Int]) async {
12+
defer {
13+
process(data: data, completion: { print($0) })
14+
}
15+
16+
func b() {
17+
process(data: data, completion: { print($0) })
18+
}
19+
// expected-warning@+1{{consider using asynchronous alternative function}}
20+
process(data: data, completion: { print($0) })
21+
}
22+
}

0 commit comments

Comments
 (0)