mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeComplete] Try to substitute archetypes with actual types in code completion results.
When completing type members, teach the code completion engine to transform the archetypes appearing in code completion results to the actual types. NFC Swift SVN r31628
This commit is contained in:
@@ -2778,3 +2778,30 @@ bool swift::typeCheckUnresolvedExpr(DeclContext &DC,
|
||||
}
|
||||
return !PossibleTypes.empty();
|
||||
}
|
||||
|
||||
Type swift::checkMemberType(DeclContext &DC, Type BaseTy,
|
||||
ArrayRef<Identifier> Names) {
|
||||
ConstraintSystemOptions Options = ConstraintSystemFlags::AllowFixes;
|
||||
auto *TypeChecker = static_cast<class TypeChecker*>(DC.getASTContext().
|
||||
getLazyResolver());
|
||||
ConstraintSystem CS(*TypeChecker, &DC, Options);
|
||||
auto Loc = CS.getConstraintLocator(nullptr);
|
||||
|
||||
Type Ty = BaseTy;
|
||||
for (auto Id : Names) {
|
||||
auto TV = CS.createTypeVariable(CS.getConstraintLocator(nullptr),
|
||||
TypeVariableOptions::TVO_CanBindToLValue);
|
||||
CS.addConstraint(Constraint::createDisjunction(CS, {
|
||||
Constraint::create(CS, ConstraintKind::TypeMember, Ty,
|
||||
TV, DeclName(Id), Loc),
|
||||
Constraint::create(CS, ConstraintKind::ValueMember, Ty,
|
||||
TV, DeclName(Id), Loc)
|
||||
}, Loc));
|
||||
Ty = TV;
|
||||
}
|
||||
assert(Ty->getKind() == TypeKind::TypeVariable && "Type is not variable");
|
||||
if (auto OS = CS.solveSingle()) {
|
||||
return OS.getValue().typeBindings[Ty->getAs<TypeVariableType>()];
|
||||
}
|
||||
return Type();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user