Skip to content

Commit 2c0b8ac

Browse files
authored
Merge pull request #36517 from ahoppen/pr/rdar64141399
[CodeComplete] Fix code completion of initialization for variable wrapped by generic property wrapper
2 parents 88bb1e2 + 28ee60e commit 2c0b8ac

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

lib/AST/Type.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4124,6 +4124,13 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
41244124
continue;
41254125
}
41264126

4127+
// There are no subtitutions to apply if the type is still unbound,
4128+
// continue looking into the parent.
4129+
if (auto unboundGeneric = baseTy->getAs<UnboundGenericType>()) {
4130+
baseTy = unboundGeneric->getParent();
4131+
continue;
4132+
}
4133+
41274134
// Assert and break to avoid hanging if we get an unexpected baseTy.
41284135
assert(0 && "Bad base type");
41294136
break;

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate(
562562
(void)var->getInterfaceType();
563563
if (!binding->isInitializerChecked(index))
564564
TypeChecker::typeCheckPatternBinding(binding, index);
565+
if (binding->isInvalid())
566+
return Type();
565567
} else {
566568
using namespace constraints;
567569
auto dc = var->getInnermostDeclContext();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_GENERIC -source-filename=%s
2+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=COMPLETE_IN_GENERIC_CONTEXT -source-filename=%s
3+
4+
struct Foo {
5+
static let bar: Foo
6+
}
7+
8+
@propertyWrapper public struct GenericWrapper<Value> {
9+
public var wrappedValue: Value
10+
public var projectedValue: Int
11+
12+
public init(wrappedValue: Value) {
13+
self.wrappedValue = wrappedValue
14+
self.projectedValue = 1
15+
}
16+
}
17+
18+
public struct GenericContext<T> {
19+
@propertyWrapper public struct GenericWrapper<Value> {
20+
public var wrappedValue: Value
21+
public var projectedValue: Int
22+
23+
public init(wrappedValue: Value) {
24+
self.wrappedValue = wrappedValue
25+
self.projectedValue = 1
26+
}
27+
}
28+
}
29+
30+
public struct MyStruct {
31+
@GenericWrapper var someProperty = #^COMPLETE_GENERIC^#
32+
}
33+
public struct MyStruct2 {
34+
@GenericContext<Foo>.GenericWrapper var someProperty2 = #^COMPLETE_IN_GENERIC_CONTEXT^#
35+
}

0 commit comments

Comments
 (0)