Skip to content

Commit 57e1732

Browse files
author
Nathan Hawes
authored
Merge pull request swiftlang#26919 from nathawes/r54219186-interpolated-string-code-completion-crash
[code-completion] Don't delay parsing a decl within a closure - delay the decl containing that closure instead
2 parents facd27f + 746340f commit 57e1732

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3149,7 +3149,8 @@ Parser::parseDecl(ParseDeclOptions Flags,
31493149

31503150
if (DeclResult.hasCodeCompletion() && isCodeCompletionFirstPass() &&
31513151
!CurDeclContext->isModuleScopeContext() &&
3152-
!isa<TopLevelCodeDecl>(CurDeclContext)) {
3152+
!isa<TopLevelCodeDecl>(CurDeclContext) &&
3153+
!isa<AbstractClosureExpr>(CurDeclContext)) {
31533154
// Only consume non-toplevel decls.
31543155
consumeDecl(BeginParserPosition, Flags, /*IsTopLevel=*/false);
31553156

test/IDE/complete_in_closures.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_IIFE_3 | %FileCheck %s -check-prefix=IN_IIFE_1
5757
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IN_IIFE_4 | %FileCheck %s -check-prefix=IN_IIFE_1
5858
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ERROR_IN_CLOSURE_IN_INITIALIZER | %FileCheck %s -check-prefix=ERROR_IN_CLOSURE_IN_INITIALIZER
59+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=DECL_IN_CLOSURE_IN_TOPLEVEL_INIT | %FileCheck %s -check-prefix=DECL_IN_CLOSURE_IN_TOPLEVEL_INIT
5960

6061
// ERROR_COMMON: found code completion token
6162
// ERROR_COMMON-NOT: Begin completions
@@ -389,3 +390,14 @@ class C {
389390
}()
390391
}
391392

393+
var foo = {
394+
let x = "Siesta:\(3)".#^DECL_IN_CLOSURE_IN_TOPLEVEL_INIT^#
395+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT: Begin completions
396+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT-DAG: Keyword[self]/CurrNominal: self[#String#]; name=self
397+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT-DAG: Decl[InstanceVar]/CurrNominal: count[#Int#]; name=count
398+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT-DAG: Decl[InstanceVar]/CurrNominal: unicodeScalars[#String.UnicodeScalarView#]; name=unicodeScalars
399+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT-DAG: Decl[InstanceMethod]/CurrNominal: hasPrefix({#(prefix): String#})[#Bool#]; name=hasPrefix(prefix: String)
400+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT-DAG: Decl[InstanceVar]/CurrNominal: utf16[#String.UTF16View#]; name=utf16
401+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT-DAG: Decl[InstanceMethod]/Super: dropFirst()[#Substring#]; name=dropFirst()
402+
// DECL_IN_CLOSURE_IN_TOPLEVEL_INIT: End completions
403+
}

0 commit comments

Comments
 (0)