Sema: Fixes for generic typealiases and nested type lookup

This patch contains several intertwined changes:

- Remove some unnecessary complexity and duplication.

- Adds a new TypeChecker::lookupUnqualifiedType() which bypasses most of
  the logic in TypeChecker::lookupUnqualified(), such as the
  LookupResultBuilder. Use this when resolving unqualified references
  to types.

- Fixes for generic typealiases to better preserve the type parameters of
  the parent type, and clean up the logic for applying the inner generic
  arguments. Some uses of generic typealiases that used to crash now work,
  and those tests have been uncommented.

- Avoid an unnecessary desugaring of TypeAliasDecls which map directly
  to GenericTypeParamTypes. Once again this perturbs the source-stability
  test.

- When looking up a nested type of a base class with a derived class base,
  always use the base class as the parent of the nested type. This fixes
  a recent regression where in some cases we were using the wrong parent.

Fixes <rdar://problem/29782186>.
This commit is contained in:
Slava Pestov
2017-01-01 18:28:55 -08:00
parent 9a389d5259
commit a598ed68e6
11 changed files with 203 additions and 207 deletions

View File

@@ -398,14 +398,17 @@ namespace {
// Open up unbound generic types, turning them into bound generic
// types with type variables for each parameter.
if (auto unbound = type->getAs<UnboundGenericType>()) {
auto parentTy = unbound->getParent();
if (parentTy)
parentTy = parentTy.transform(*this);
auto unboundDecl = unbound->getDecl();
if (unboundDecl->isInvalid())
return ErrorType::get(cs.getASTContext());
auto parentTy = unbound->getParent();
if (parentTy) {
parentTy = parentTy.transform(*this);
unbound = UnboundGenericType::get(unboundDecl, parentTy,
cs.getASTContext());
}
// If the unbound decl hasn't been validated yet, we have a circular
// dependency that isn't being diagnosed properly.
if (!unboundDecl->getGenericSignature()) {
@@ -747,8 +750,6 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
auto type = getTypeChecker().resolveTypeInContext(typeDecl, DC,
TR_InExpression,
isSpecialized);
if (!type)
return { nullptr, nullptr };
// Open the type.
type = openType(type, locator, replacements);