Sema: Better support for nested generic functions

There was a weird corner case with nested generic functions that
would fail in the SIL verifier with some nonsense about archetypes
out of context.

Fix this the "right" way, by re-working Sema function declaration
validation to assign generic signatures in a more principled way.

Previously, nested functions did not get an interface type unless
they themselves had generic parameters.

This was inconsistent with methods nested inside generic types,
which did get an interface type even if they themselves did not
have a generic parameter list.

There's some spill-over in SILGen from this change. Mostly it
makes things more consistent and fixes some corner cases.
This commit is contained in:
Slava Pestov
2016-06-08 23:20:00 -07:00
parent fef525750b
commit bbefeb2fc5
34 changed files with 148 additions and 154 deletions

View File

@@ -726,6 +726,13 @@ TypeBase::gatherAllSubstitutions(Module *module,
llvm_unreachable("Not a nominal or bound generic type");
}
// Add forwarding substitutions from the outer context if we have
// a type nested inside a generic function.
if (auto *outerGenericParams = parentDC->getGenericParamsOfContext()) {
for (auto archetype : outerGenericParams->getAllNestedArchetypes())
substitutions[archetype] = archetype;
}
// Collect all of the archetypes.
SmallVector<ArchetypeType *, 2> allArchetypesList;
ArrayRef<ArchetypeType *> allArchetypes = genericParams->getAllArchetypes();