mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
TypeResolution: Stop resolving unqualified protocol type aliases to DependentMemberType in structural stage
This workaround is no longer needed because `TypeAliasType` is now modeled using generic arguments (as opposed to a substitution map). Previously, computing the substitution map in `StructuralTypeRequest` to construct the resulting `TypeAliasType` could cause a request cycle around generic signature computation.
This commit is contained in:
@@ -1127,11 +1127,6 @@ Type StructuralTypeRequest::evaluate(Evaluator &evaluator,
|
||||
/*packElementOpener*/ nullptr)
|
||||
.resolveType(underlyingTypeRepr);
|
||||
|
||||
// Don't build a generic siganture for a protocol extension, because this
|
||||
// request might be evaluated while building a protocol requirement signature.
|
||||
if (parentDC->getSelfProtocolDecl())
|
||||
return result;
|
||||
|
||||
Type parent;
|
||||
if (parentDC->isTypeContext())
|
||||
parent = parentDC->getSelfInterfaceType();
|
||||
|
||||
@@ -560,15 +560,17 @@ Type TypeResolution::resolveTypeInContext(TypeDecl *typeDecl,
|
||||
selfType = foundDC->getSelfInterfaceType();
|
||||
|
||||
if (selfType->is<GenericTypeParamType>()) {
|
||||
if (isa<ProtocolDecl>(typeDecl->getDeclContext())) {
|
||||
if (isa<AssociatedTypeDecl>(typeDecl) ||
|
||||
(isa<TypeAliasDecl>(typeDecl) &&
|
||||
!cast<TypeAliasDecl>(typeDecl)->isGeneric() &&
|
||||
!isSpecialized)) {
|
||||
if (getStage() == TypeResolutionStage::Structural) {
|
||||
return DependentMemberType::get(selfType, typeDecl->getName());
|
||||
} else if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
|
||||
typeDecl = assocType->getAssociatedTypeAnchor();
|
||||
if (auto assocType = dyn_cast<AssociatedTypeDecl>(typeDecl)) {
|
||||
if (getStage() == TypeResolutionStage::Structural) {
|
||||
return DependentMemberType::get(selfType, typeDecl->getName());
|
||||
}
|
||||
|
||||
typeDecl = assocType->getAssociatedTypeAnchor();
|
||||
} else if (auto *aliasDecl = dyn_cast<TypeAliasDecl>(typeDecl)) {
|
||||
if (isa<ProtocolDecl>(typeDecl->getDeclContext()) &&
|
||||
getStage() == TypeResolutionStage::Structural) {
|
||||
if (aliasDecl && !aliasDecl->isGeneric()) {
|
||||
return adjustAliasType(aliasDecl->getStructuralType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
test/type/explicit_existential_protocol_typealias.swift
Normal file
16
test/type/explicit_existential_protocol_typealias.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
// RUN: %target-typecheck-verify-swift -target %target-swift-5.9-abi-triple -enable-upcoming-feature ExistentialAny
|
||||
|
||||
// REQUIRES: swift_feature_ExistentialAny
|
||||
|
||||
protocol P {
|
||||
typealias PAlias1 = P
|
||||
|
||||
func f1() -> any PAlias1
|
||||
func g1<T>(_: T) -> any PAlias1
|
||||
}
|
||||
extension P {
|
||||
typealias PAlias2 = P
|
||||
|
||||
func f2() -> any PAlias2 {}
|
||||
func g2<T>(_: T) -> any PAlias2 {}
|
||||
}
|
||||
Reference in New Issue
Block a user