mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Fix for archetypes leaking through when resolving generic type alias
Also make the existing assertion for this stricter. Previously, we were calling hasArchetype() on a GenericFunctionType, which is always false (along with hasTypeParameter()) since generic function types don't have any free type parameters in them. Fixes <rdar://problem/27405113>.
This commit is contained in:
@@ -638,6 +638,11 @@ void TypeChecker::configureInterfaceType(AbstractFunctionDecl *func) {
|
||||
if (i == 0 && func->hasThrows())
|
||||
info = info.withThrows();
|
||||
|
||||
assert(!argTy->hasArchetype());
|
||||
assert(!funcTy->hasArchetype());
|
||||
if (initFuncTy)
|
||||
assert(!initFuncTy->hasArchetype());
|
||||
|
||||
if (sig && i == e-1) {
|
||||
funcTy = GenericFunctionType::get(sig, argTy, funcTy, info);
|
||||
if (initFuncTy)
|
||||
@@ -650,12 +655,9 @@ void TypeChecker::configureInterfaceType(AbstractFunctionDecl *func) {
|
||||
}
|
||||
|
||||
// Record the interface type.
|
||||
assert(!funcTy->hasArchetype());
|
||||
func->setInterfaceType(funcTy);
|
||||
if (initFuncTy) {
|
||||
assert(!initFuncTy->hasArchetype());
|
||||
if (initFuncTy)
|
||||
cast<ConstructorDecl>(func)->setInitializerInterfaceType(initFuncTy);
|
||||
}
|
||||
|
||||
if (func->getGenericParams()) {
|
||||
// Collect all generic params referenced in parameter types,
|
||||
|
||||
@@ -519,8 +519,7 @@ Type TypeChecker::applyUnboundGenericArguments(
|
||||
if (auto outerSig = TAD->getDeclContext()->getGenericSignatureOfContext()) {
|
||||
for (auto outerParam : outerSig->getGenericParams()) {
|
||||
subs[outerParam->getCanonicalType().getPointer()] =
|
||||
ArchetypeBuilder::mapTypeIntoContext(TAD->getDeclContext(),
|
||||
outerParam);
|
||||
resolver->resolveGenericTypeParamType(outerParam);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -164,6 +164,12 @@ class GenericClass<T> {
|
||||
}
|
||||
}
|
||||
|
||||
let gc = GenericClass<Double>()
|
||||
let fn: MyType<Double, Int> = gc.testCapture(s: 1, t: 1.0)
|
||||
|
||||
func use<T>(_ t: T) {}
|
||||
use(fn)
|
||||
|
||||
// Make sure we apply base substitutions to the interface type of the typealias
|
||||
class ConcreteClass : GenericClass<String> {
|
||||
func testSubstitutedCapture1<S>(s: S, t: String) -> TA<S> {
|
||||
|
||||
Reference in New Issue
Block a user