Revert "IUO: Add support for non-subscript dynamic lookup."

This commit is contained in:
Mark Lacey
2018-01-10 22:53:56 -08:00
committed by GitHub
parent 82b36b8e75
commit 43aebc832e
5 changed files with 6 additions and 69 deletions

View File

@@ -1512,9 +1512,6 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
// Determine the type to which we'll bind the overload set's type.
Type refType;
Type openedFullType;
bool isDynamicResult = choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
switch (auto kind = choice.getKind()) {
case OverloadChoiceKind::Decl:
// If we refer to a top-level decl with special type-checking semantics,
@@ -1528,6 +1525,8 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
case OverloadChoiceKind::DeclViaBridge:
case OverloadChoiceKind::DeclViaDynamic:
case OverloadChoiceKind::DeclViaUnwrappedOptional: {
bool isDynamicResult
= choice.getKind() == OverloadChoiceKind::DeclViaDynamic;
// Retrieve the type of a reference to the specific declaration choice.
if (auto baseTy = choice.getBaseType()) {
assert(!baseTy->hasTypeParameter());
@@ -1571,7 +1570,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
// Subscript declarations are handled within
// getTypeOfMemberReference(); their result types are optional.
refType = OptionalType::get(refType->getRValueType());
}
}
// For a non-subscript declaration found via dynamic lookup, strip
// off the lvalue-ness (FIXME: as a temporary hack. We eventually
// want this to work) and make a reference to that declaration be
@@ -1580,37 +1579,9 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
// Subscript declarations are handled within
// getTypeOfMemberReference(); their result types are unchecked
// optional.
else if (isDynamicResult && !isa<SubscriptDecl>(choice.getDecl())) {
Type ty = refType;
// If this is something we need to implicitly unwrap, set up a
// new type variable and disjunction that will allow us to make
// the choice of whether to do so.
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
// Duplicate the structure of boundType, with fresh type
// variables. We'll create a binding disjunction using this,
// selecting between options for refType, which is either
// Optional or a function type returning Optional.
assert(boundType->hasTypeVariable());
Type ty = boundType.transform([this](Type elTy) -> Type {
if (auto *tv = dyn_cast<TypeVariableType>(elTy.getPointer())) {
return createTypeVariable(tv->getImpl().getLocator(),
tv->getImpl().getRawOptions());
}
return elTy;
});
buildDisjunctionForImplicitlyUnwrappedOptional(ty, refType, locator);
}
// Build the disjunction to attempt binding both T? and T (or
// function returning T? and function returning T).
buildDisjunctionForDynamicLookupResult(
boundType, ImplicitlyUnwrappedOptionalType::get(ty->getRValueType()),
locator);
else if (isDynamicResult && !isa<SubscriptDecl>(choice.getDecl())) {
refType = ImplicitlyUnwrappedOptionalType::get(refType->getRValueType());
}
}
// If the declaration is unavailable, note that in the score.
if (choice.getDecl()->getAttrs().isUnavailable(getASTContext())) {
@@ -1698,8 +1669,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
openedFullType,
refType};
// We created appropriate disjunctions for dynamic result above.
if (!isDynamicResult && choice.isImplicitlyUnwrappedValueOrReturnValue()) {
if (choice.isImplicitlyUnwrappedValueOrReturnValue()) {
// Build the disjunction to attempt binding both T? and T (or
// function returning T? and function returning T).
buildDisjunctionForImplicitlyUnwrappedOptional(boundType, refType, locator);