|
29 | 29 | #include "llvm/ADT/SmallPtrSet.h"
|
30 | 30 | using namespace swift;
|
31 | 31 |
|
32 |
| -static SourceLoc getCaptureLoc(AnyFunctionRef AFR) { |
33 |
| - if (auto AFD = AFR.getAbstractFunctionDecl()) { |
34 |
| - if (auto *FD = dyn_cast<FuncDecl>(AFD)) { |
35 |
| - if (FD->isDeferBody()) { |
36 |
| - // HACK: Defer statements generate implicit FuncDecls, and hence do |
37 |
| - // not have valid source locations. Instead, use the location of |
38 |
| - // the body. |
39 |
| - return FD->getBody()->getLBraceLoc(); |
40 |
| - } |
41 |
| - } |
42 |
| - |
43 |
| - return AFD->getLoc(); |
44 |
| - } else { |
45 |
| - auto ACE = AFR.getAbstractClosureExpr(); |
46 |
| - if (auto CE = dyn_cast<ClosureExpr>(ACE)) { |
47 |
| - if (!CE->getInLoc().isInvalid()) |
48 |
| - return CE->getInLoc(); |
49 |
| - } |
50 |
| - |
51 |
| - return ACE->getLoc(); |
52 |
| - } |
53 |
| -} |
54 |
| - |
55 | 32 | namespace {
|
56 | 33 |
|
57 | 34 | class FindCapturedVars : public ASTWalker {
|
@@ -80,7 +57,7 @@ class FindCapturedVars : public ASTWalker {
|
80 | 57 | DynamicSelf(DynamicSelf),
|
81 | 58 | OpaqueValue(OpaqueValue),
|
82 | 59 | AFR(AFR) {
|
83 |
| - CaptureLoc = getCaptureLoc(AFR); |
| 60 | + CaptureLoc = AFR.getLoc(); |
84 | 61 | }
|
85 | 62 |
|
86 | 63 | /// Check if the type of an expression references any generic
|
@@ -355,11 +332,11 @@ class FindCapturedVars : public ASTWalker {
|
355 | 332 |
|
356 | 333 | if (GenericParamCaptureLoc.isInvalid())
|
357 | 334 | if (captureInfo.hasGenericParamCaptures())
|
358 |
| - GenericParamCaptureLoc = getCaptureLoc(innerClosure); |
| 335 | + GenericParamCaptureLoc = innerClosure.getLoc(); |
359 | 336 |
|
360 | 337 | if (DynamicSelfCaptureLoc.isInvalid())
|
361 | 338 | if (captureInfo.hasDynamicSelfCapture()) {
|
362 |
| - DynamicSelfCaptureLoc = getCaptureLoc(innerClosure); |
| 339 | + DynamicSelfCaptureLoc = innerClosure.getLoc(); |
363 | 340 | DynamicSelf = captureInfo.getDynamicSelfType();
|
364 | 341 | }
|
365 | 342 |
|
@@ -643,7 +620,7 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
|
643 | 620 | AFR.getBody()->walk(finder);
|
644 | 621 |
|
645 | 622 | if (AFR.hasType() && !AFR.isObjC()) {
|
646 |
| - finder.checkType(AFR.getType(), getCaptureLoc(AFR)); |
| 623 | + finder.checkType(AFR.getType(), AFR.getLoc()); |
647 | 624 | }
|
648 | 625 |
|
649 | 626 | // If this is an init(), explicitly walk the initializer values for members of
|
|
0 commit comments