[CodeCompletion] Expr context type analysis for failed array literal expr

let _: [Foo] = [
  .create(str: Int)
  .create(#^COMPLETE^#)
]

Previously, this completion used to fail because the array expression
isn't typechecked. We need to analyze the context type of the array
literal first, that defines the type of the unresolved member
expression.

rdar://problem/50696432
This commit is contained in:
Rintaro Ishizaki
2019-07-18 21:27:39 -07:00
parent da61cc8cdf
commit ee2f39cc21
2 changed files with 50 additions and 0 deletions

View File

@@ -583,6 +583,15 @@ class ExprContextAnalyzer {
case ExprKind::Array: {
if (auto type = ParsedExpr->getType()) {
recordPossibleType(type);
break;
}
// Check context types of the array literal expression.
ExprContextInfo arrayCtxtInfo(DC, Parent);
for (auto arrayT : arrayCtxtInfo.getPossibleTypes()) {
if (auto boundGenericT = arrayT->getAs<BoundGenericType>())
if (boundGenericT->getDecl() == Context.getArrayDecl())
recordPossibleType(boundGenericT->getGenericArgs()[0]);
}
break;
}