Skip to content

Fixes SR-642: Code completion does not instantiate generic arguments of a type wrapped in an optional. #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3182,7 +3182,7 @@ DEFINE_EMPTY_CAN_TYPE_WRAPPER(SILBlockStorageType, Type)

/// A type with a special syntax that is always sugar for a library type.
///
/// The prime examples are arrays (T[] -> Array<T>) and
/// The prime examples are arrays ([T] -> Array<T>) and
/// optionals (T? -> Optional<T>).
class SyntaxSugarType : public TypeBase {
Type Base;
Expand Down
5 changes: 3 additions & 2 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,9 +1708,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
Type ContextTy = VD->getDeclContext()->getDeclaredTypeOfContext();
if (ContextTy) {
Type MaybeNominalType = ExprType->getRValueInstanceType();
if (ContextTy->getAnyNominal() == MaybeNominalType->getAnyNominal() &&
if (ContextTy->lookThroughAllAnyOptionalTypes()->getAnyNominal() ==
MaybeNominalType->lookThroughAllAnyOptionalTypes()->getAnyNominal() &&
!isBoringBoundGenericType(MaybeNominalType)) {
if (Type T = MaybeNominalType->getTypeOfMember(
if (Type T = MaybeNominalType->lookThroughAllAnyOptionalTypes()->getTypeOfMember(
CurrDeclContext->getParentModule(), VD, TypeResolver.get()))
return TransformerPt ? T.transform(TransformerPt->getTransformerFunc()) :
T;
Expand Down
16 changes: 16 additions & 0 deletions test/IDE/complete_generic_optional.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=FOO_OPTIONAL_1 | FileCheck %s -check-prefix=FOO_OPTIONAL_1

struct Bar {
}

struct Foo<T> {
func myFunction(foobar: T) {
}
}

// SR-642 Code completion does not instantiate generic arguments of a type wrapped in an optional
let x: Foo<Bar>? = Foo<Bar>()
x.#^FOO_OPTIONAL_1^#
// FOO_OPTIONAL_1: Begin completions, 4 items
// FOO_OPTIONAL_1-DAG: Decl[InstanceMethod]/CurrNominal/Erase[1]: ?.myFunction({#(foobar): Bar#})[#Void#]; name=myFunction(foobar: Bar)
// FOO_OPTIONAL_1: End completions