Skip to content
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

[CodeComplete] Fix code completion of initialization for variable wrapped by generic property wrapper #36517

Merged
merged 1 commit into from Mar 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/AST/Type.cpp
Expand Up @@ -4108,6 +4108,13 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
continue;
}

// There are no subtitutions to apply if the type is still unbound,
// continue looking into the parent.
if (auto unboundGeneric = baseTy->getAs<UnboundGenericType>()) {
baseTy = unboundGeneric->getParent();
continue;
}

// Assert and break to avoid hanging if we get an unexpected baseTy.
assert(0 && "Bad base type");
break;
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckPropertyWrapper.cpp
Expand Up @@ -565,6 +565,8 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
(void)var->getInterfaceType();
if (!binding->isInitializerChecked(index))
TypeChecker::typeCheckPatternBinding(binding, index);
if (binding->isInvalid())
return Type();
} else {
using namespace constraints;
auto dc = var->getInnermostDeclContext();
Expand Down
@@ -0,0 +1,35 @@
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_GENERIC -source-filename=%s
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_IN_GENERIC_CONTEXT -source-filename=%s

struct Foo {
static let bar: Foo
}

@propertyWrapper public struct GenericWrapper<Value> {
public var wrappedValue: Value
public var projectedValue: Int

public init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
self.projectedValue = 1
}
}

public struct GenericContext<T> {
@propertyWrapper public struct GenericWrapper<Value> {
public var wrappedValue: Value
public var projectedValue: Int

public init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
self.projectedValue = 1
}
}
}

public struct MyStruct {
@GenericWrapper var someProperty = #^COMPLETE_GENERIC^#
}
public struct MyStruct2 {
@GenericContext<Foo>.GenericWrapper var someProperty2 = #^COMPLETE_IN_GENERIC_CONTEXT^#
}