Skip to content

Commit 35cbdd8

Browse files
authored
Merge pull request #82803 from hamishknight/context-fail-6.2
[6.2] [Completion] Map failable initializer result type into context
2 parents 86bf714 + 9671ed9 commit 35cbdd8

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ static void addKeywordsAfterReturn(CodeCompletionResultSink &Sink, DeclContext *
901901
// Note that `TypeContext` must stay alive for the duration of
902902
// `~CodeCodeCompletionResultBuilder()`.
903903
ExpectedTypeContext TypeContext;
904-
TypeContext.setPossibleTypes({resultType});
904+
TypeContext.setPossibleTypes({DC->mapTypeIntoContext(resultType)});
905905

906906
CodeCompletionResultBuilder Builder(Sink, CodeCompletionResultKind::Literal,
907907
SemanticContextKind::None);

test/IDE/complete_keywords.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ struct InInit {
377377
init?() { #^IN_INIT_1?check=KW_DECL_STMT;check=KW_RETURN;check=KW_NO_IN^# }
378378
}
379379

380+
struct InGenericTypeInit<T> {
381+
init?() { return #^IN_INIT_2?check=KW_FAILABLE_INIT_NIL^# }
382+
// KW_FAILABLE_INIT_NIL: Literal[Nil]/None: nil[#InGenericTypeInit<T>?#]; name=nil
383+
}
384+
380385
struct InStruct {
381386
#^IN_NOMINAL_DECL_1?check=KW_DECL_TYPECONTEXT;check=KW_NO_INOUT^#
382387
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// {"kind":"complete","signature":"swift::ide::CodeCompletionResultType::calculateTypeRelation(swift::ide::ExpectedTypeContext const*, swift::DeclContext const*, swift::ide::USRBasedTypeContext const*) const"}
2+
// RUN: %target-swift-ide-test -code-completion --code-completion-token=COMPLETE -source-filename %s
3+
class a<b { init ? { #^COMPLETE^#

0 commit comments

Comments
 (0)