Skip to content

Commit 6da1be5

Browse files
authored
Merge pull request #25130 from rintaro/ide-mangledtype-rdar51198887
[TypeContextInfo/ConformingMethods] Map type out of context
2 parents 29a8dbf + 5ff4b0c commit 6da1be5

12 files changed

+216
-2
lines changed

lib/IDE/ConformingMethodList.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ void ConformingMethodListCallbacks::doneParsing() {
8787
if (!T || T->is<ErrorType>() || T->is<UnresolvedType>())
8888
return;
8989

90+
T = T->getRValueType();
91+
if (T->hasArchetype())
92+
T = T->mapTypeOutOfContext();
93+
9094
llvm::MapVector<ProtocolDecl*, StringRef> expectedProtocols;
9195
resolveProtocolNames(CurDeclContext, ExpectedTypeNames, expectedProtocols);
9296

lib/IDE/TypeContextInfo.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,17 @@ void ContextInfoCallbacks::doneParsing() {
104104
for (auto T : Info.getPossibleTypes()) {
105105
if (T->is<ErrorType>() || T->is<UnresolvedType>())
106106
continue;
107-
if (auto env = CurDeclContext->getGenericEnvironmentOfContext())
108-
T = env->mapTypeIntoContext(T);
107+
108+
T = T->getRValueType();
109+
if (T->hasArchetype())
110+
T = T->mapTypeOutOfContext();
109111

110112
// TODO: Do we need '.none' for Optionals?
111113
auto objT = T->lookThroughAllOptionalTypes();
112114

115+
if (auto env = CurDeclContext->getGenericEnvironmentOfContext())
116+
objT = env->mapTypeIntoContext(T);
117+
113118
if (!seenTypes.insert(objT->getCanonicalType()).second)
114119
continue;
115120

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
protocol Proto {}
2+
struct ConcreteProto : Proto {}
3+
struct ConcreteProtoGen<T> : Proto {}
4+
5+
struct S<T> : Proto {
6+
func methodForProto1(x: T) -> ConcreteProto {}
7+
func methodForProto2<U>(x: U) -> ConcreteProtoGen<U> {}
8+
func methodForProto3(x: Self) -> ConcreteProtoGen<T> {}
9+
func methodForProto4() -> Self {}
10+
func methodForInt() -> Int { return 1 }
11+
mutating func test() {
12+
self.
13+
}
14+
}
15+
16+
func test<X>(value: S<X>) {
17+
value.
18+
}
19+
20+
// RUN: %sourcekitd-test -req=conformingmethods -pos=12:10 %s -req-opts=expectedtypes='$s8MyModule5ProtoPD' -- -module-name MyModule %s > %t.response.1
21+
// RUN: diff -u %s.response.1 %t.response.1
22+
// RUN: %sourcekitd-test -req=conformingmethods -pos=17:8 %s -req-opts=expectedtypes='$s8MyModule5ProtoPD' -- -module-name MyModule %s > %t.response.2
23+
// RUN: diff -u %s.response.2 %t.response.2
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
key.typename: "S<T>",
3+
key.typeusr: "$s8MyModule1SVyxGD",
4+
key.members: [
5+
{
6+
key.name: "methodForProto1(x:)",
7+
key.sourcetext: "methodForProto1(x: <#T##T#>)",
8+
key.description: "methodForProto1(x: T)",
9+
key.typename: "ConcreteProto",
10+
key.typeusr: "$s8MyModule13ConcreteProtoVD"
11+
},
12+
{
13+
key.name: "methodForProto2(x:)",
14+
key.sourcetext: "methodForProto2(x: <#T##U#>)",
15+
key.description: "methodForProto2(x: U)",
16+
key.typename: "ConcreteProtoGen<U>",
17+
key.typeusr: "$s8MyModule16ConcreteProtoGenVyqd__GD"
18+
},
19+
{
20+
key.name: "methodForProto3(x:)",
21+
key.sourcetext: "methodForProto3(x: <#T##S<T>#>)",
22+
key.description: "methodForProto3(x: S<T>)",
23+
key.typename: "ConcreteProtoGen<T>",
24+
key.typeusr: "$s8MyModule16ConcreteProtoGenVyxGD"
25+
},
26+
{
27+
key.name: "methodForProto4()",
28+
key.sourcetext: "methodForProto4()",
29+
key.description: "methodForProto4()",
30+
key.typename: "S<T>",
31+
key.typeusr: "$s8MyModule1SVyxGD"
32+
}
33+
]
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
key.typename: "S<X>",
3+
key.typeusr: "$s8MyModule1SVyxGD",
4+
key.members: [
5+
{
6+
key.name: "methodForProto1(x:)",
7+
key.sourcetext: "methodForProto1(x: <#T##X#>)",
8+
key.description: "methodForProto1(x: X)",
9+
key.typename: "ConcreteProto",
10+
key.typeusr: "$s8MyModule13ConcreteProtoVD"
11+
},
12+
{
13+
key.name: "methodForProto2(x:)",
14+
key.sourcetext: "methodForProto2(x: <#T##U#>)",
15+
key.description: "methodForProto2(x: U)",
16+
key.typename: "ConcreteProtoGen<U>",
17+
key.typeusr: "$s8MyModule16ConcreteProtoGenVyqd__GD"
18+
},
19+
{
20+
key.name: "methodForProto3(x:)",
21+
key.sourcetext: "methodForProto3(x: <#T##S<X>#>)",
22+
key.description: "methodForProto3(x: S<X>)",
23+
key.typename: "ConcreteProtoGen<X>",
24+
key.typeusr: "$s8MyModule16ConcreteProtoGenVyxGD"
25+
},
26+
{
27+
key.name: "methodForProto4()",
28+
key.sourcetext: "methodForProto4()",
29+
key.description: "methodForProto4()",
30+
key.typename: "S<X>",
31+
key.typeusr: "$s8MyModule1SVyxGD"
32+
}
33+
]
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
struct S<T> {
2+
func foo<U>(x: U) {}
3+
func bar<V>(x: S<V>) {}
4+
func baz(x: Self) {}
5+
6+
func test() {
7+
foo(x: )
8+
bar(x: )
9+
self.baz(x: )
10+
}
11+
12+
func test2<X>(x: X) {
13+
var value = S<X>()
14+
value.foo(x: )
15+
value.bar(x: )
16+
value.baz(x: )
17+
}
18+
19+
static var instance: Self = S<T>()
20+
}
21+
22+
// RUN: %sourcekitd-test -req=typecontextinfo -pos=7:12 %s -- %s > %t.response.1
23+
// RUN: diff -u %s.response.1 %t.response.1
24+
// RUN: %sourcekitd-test -req=typecontextinfo -pos=8:12 %s -- %s > %t.response.2
25+
// RUN: diff -u %s.response.2 %t.response.2
26+
// RUN: %sourcekitd-test -req=typecontextinfo -pos=9:17 %s -- %s > %t.response.3
27+
// RUN: diff -u %s.response.3 %t.response.3
28+
29+
// RUN: %sourcekitd-test -req=typecontextinfo -pos=14:18 %s -- %s > %t.response.4
30+
// RUN: diff -u %s.response.4 %t.response.4
31+
// RUN: %sourcekitd-test -req=typecontextinfo -pos=15:18 %s -- %s > %t.response.5
32+
// RUN: diff -u %s.response.5 %t.response.5
33+
// RUN: %sourcekitd-test -req=typecontextinfo -pos=16:18 %s -- %s > %t.response.6
34+
// RUN: diff -u %s.response.6 %t.response.6
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
key.results: [
3+
{
4+
key.typename: "U",
5+
key.typeusr: "$sqd__D",
6+
key.implicitmembers: [
7+
]
8+
}
9+
]
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
key.results: [
3+
{
4+
key.typename: "S<V>",
5+
key.typeusr: "$s20typecontext_generics1SVyqd__GD",
6+
key.implicitmembers: [
7+
{
8+
key.name: "instance",
9+
key.sourcetext: "instance",
10+
key.description: "instance"
11+
}
12+
]
13+
}
14+
]
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
key.results: [
3+
{
4+
key.typename: "S<T>",
5+
key.typeusr: "$s20typecontext_generics1SVyxGD",
6+
key.implicitmembers: [
7+
{
8+
key.name: "instance",
9+
key.sourcetext: "instance",
10+
key.description: "instance"
11+
}
12+
]
13+
}
14+
]
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
key.results: [
3+
{
4+
key.typename: "U",
5+
key.typeusr: "$sqd__D",
6+
key.implicitmembers: [
7+
]
8+
}
9+
]
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
key.results: [
3+
{
4+
key.typename: "S<V>",
5+
key.typeusr: "$s20typecontext_generics1SVyqd__GD",
6+
key.implicitmembers: [
7+
{
8+
key.name: "instance",
9+
key.sourcetext: "instance",
10+
key.description: "instance"
11+
}
12+
]
13+
}
14+
]
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
key.results: [
3+
{
4+
key.typename: "S<X>",
5+
key.typeusr: "$s20typecontext_generics1SVyqd__GD",
6+
key.implicitmembers: [
7+
{
8+
key.name: "instance",
9+
key.sourcetext: "instance",
10+
key.description: "instance"
11+
}
12+
]
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)