File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed
test/SourceKit/CodeComplete Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -3766,8 +3766,9 @@ void ASTMangler::appendClosureEntity(const AbstractClosureExpr *closure) {
3766
3766
3767
3767
auto type = closure->getType ();
3768
3768
3769
- // FIXME: CodeCompletionResultBuilder calls printValueDeclUSR() but the
3770
- // closure hasn't been type checked yet.
3769
+ // FIXME: We can end up with a null type here in the presence of invalid
3770
+ // code; the type-checker currently isn't strict about producing typed
3771
+ // expression nodes when it fails. Once we enforce that, we can remove this.
3771
3772
if (!type)
3772
3773
type = ErrorType::get (closure->getASTContext ());
3773
3774
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ static bool shouldCopyAssociatedUSRForDecl(const ValueDecl *VD) {
36
36
if (VD->hasClangNode () && !VD->getClangDecl ())
37
37
return false ;
38
38
39
+ // Avoid generating USRs for decls in local contexts, we cannot guarantee
40
+ // any parent closures will be type-checked, which is needed for mangling.
41
+ if (VD->getDeclContext ()->getLocalContext ())
42
+ return false ;
43
+
39
44
return true ;
40
45
}
41
46
Original file line number Diff line number Diff line change
1
+ // rdar://128294522 - Make sure we don't generate USRs for decls in local contexts.
2
+
3
+ func test1( ) {
4
+ let loclVar = 0 // This typo is intentional; otherwise mangling applies a substitution for 'local'.
5
+ // RUN: %sourcekitd-test -req=complete -pos=%(line):3 %s -- %s | %FileCheck %s --check-prefix LOCAL_VAR
6
+ // LOCAL_VAR-NOT: key.associated_usrs: "s:{{.*}}loclVar{{.*}}"
7
+ // LOCAL_VAR: key.name: "loclVar"
8
+ // LOCAL_VAR-NOT: key.associated_usrs: "s:{{.*}}loclVar{{.*}}"
9
+ }
10
+
11
+ func test2( ) {
12
+ let _ = {
13
+ struct S {
14
+ func nestedMethod( ) {
15
+ // RUN: %sourcekitd-test -req=complete -pos=%(line):3 %s -- %s | %FileCheck %s --check-prefix LOCAL_METHOD
16
+ // RUN: %sourcekitd-test -req=complete -pos=%(line+1):14 %s -- %s | %FileCheck %s --check-prefix LOCAL_METHOD
17
+ self .
18
+ // LOCAL_METHOD-NOT: key.associated_usrs: "s:{{.*}}nestedMethod{{.*}}"
19
+ // LOCAL_METHOD: key.name: "nestedMethod()"
20
+ // LOCAL_METHOD-NOT: key.associated_usrs: "s:{{.*}}nestedMethod{{.*}}"
21
+ }
22
+ }
23
+ }
24
+ }
25
+
26
+ // Just to make sure 'key.associated_usrs' is produced for a non-local decl
27
+ // so the above CHECK-NOT's are working. If this fails, make sure to update the
28
+ // above checks too.
29
+ // RUN: %sourcekitd-test -req=complete -pos=%(line):1 %s -- %s | %FileCheck %s --check-prefix NON_LOCAL
30
+ // NON_LOCAL: key.associated_usrs: "s:{{.*}}test2{{.*}}"
You can’t perform that action at this time.
0 commit comments