@@ -3784,16 +3784,17 @@ PotentialArchetype *GenericSignatureBuilder::realizePotentialArchetype(
3784
3784
return pa;
3785
3785
}
3786
3786
3787
- static Type getStructuralType (TypeDecl *typeDecl) {
3787
+ static Type getStructuralType (TypeDecl *typeDecl, bool keepSugar ) {
3788
3788
if (auto typealias = dyn_cast<TypeAliasDecl>(typeDecl)) {
3789
- // When we're computing requirement signatures, the structural type
3790
- // suffices. Otherwise we'll potentially try to validate incomplete
3791
- // requirements.
3792
- auto *proto = dyn_cast_or_null<ProtocolDecl>(
3793
- typealias->getDeclContext ()->getAsDecl ());
3794
- if (proto && proto->isComputingRequirementSignature ())
3795
- return typealias->getStructuralType ();
3796
- return typealias->getUnderlyingType ();
3789
+ if (typealias->getUnderlyingTypeRepr () != nullptr ) {
3790
+ auto type = typealias->getStructuralType ();
3791
+ if (!keepSugar)
3792
+ if (auto *aliasTy = cast<TypeAliasType>(type.getPointer ()))
3793
+ return aliasTy->getSinglyDesugaredType ();
3794
+ return type;
3795
+ }
3796
+ if (!keepSugar)
3797
+ return typealias->getUnderlyingType ();
3797
3798
}
3798
3799
3799
3800
return typeDecl->getDeclaredInterfaceType ();
@@ -3804,43 +3805,35 @@ static Type substituteConcreteType(GenericSignatureBuilder &builder,
3804
3805
TypeDecl *concreteDecl) {
3805
3806
assert (concreteDecl);
3806
3807
3807
- auto *proto = concreteDecl->getDeclContext ()->getSelfProtocolDecl ();
3808
+ auto *dc = concreteDecl->getDeclContext ();
3809
+ auto *proto = dc->getSelfProtocolDecl ();
3808
3810
3809
3811
// Form an unsubstituted type referring to the given type declaration,
3810
3812
// for use in an inferred same-type requirement.
3811
- auto type = getStructuralType (concreteDecl);
3813
+ auto type = getStructuralType (concreteDecl, /* keepSugar= */ true );
3812
3814
if (!type)
3813
3815
return Type ();
3814
3816
3815
- Type parentType;
3816
3817
SubstitutionMap subMap;
3817
3818
if (proto) {
3818
3819
// Substitute in the type of the current PotentialArchetype in
3819
3820
// place of 'Self' here.
3820
- parentType = basePA->getDependentType (builder.getGenericParams ());
3821
+ auto parentType = basePA->getDependentType (builder.getGenericParams ());
3821
3822
3822
3823
subMap = SubstitutionMap::getProtocolSubstitutions (
3823
3824
proto, parentType, ProtocolConformanceRef (proto));
3824
-
3825
- type = type.subst (subMap);
3826
3825
} else {
3827
3826
// Substitute in the superclass type.
3828
3827
auto parentPA = basePA->getEquivalenceClassIfPresent ();
3829
- parentType =
3828
+ auto parentType =
3830
3829
parentPA->concreteType ? parentPA->concreteType : parentPA->superclass ;
3831
3830
auto parentDecl = parentType->getAnyNominal ();
3832
3831
3833
- subMap = parentType->getMemberSubstitutionMap (parentDecl->getParentModule (),
3834
- concreteDecl);
3835
- type = type.subst (subMap);
3836
- }
3837
-
3838
- // If we had a typealias, form a sugared type.
3839
- if (auto *typealias = dyn_cast<TypeAliasDecl>(concreteDecl)) {
3840
- type = TypeAliasType::get (typealias, parentType, subMap, type);
3832
+ subMap = parentType->getContextSubstitutionMap (
3833
+ parentDecl->getParentModule (), dc);
3841
3834
}
3842
3835
3843
- return type;
3836
+ return type. subst (subMap) ;
3844
3837
};
3845
3838
3846
3839
ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass (
@@ -4215,10 +4208,10 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
4215
4208
// An inferred same-type requirement between the two type declarations
4216
4209
// within this protocol or a protocol it inherits.
4217
4210
auto addInferredSameTypeReq = [&](TypeDecl *first, TypeDecl *second) {
4218
- Type firstType = getStructuralType (first);
4211
+ Type firstType = getStructuralType (first, /* keepSugar= */ false );
4219
4212
if (!firstType) return ;
4220
4213
4221
- Type secondType = getStructuralType (second);
4214
+ Type secondType = getStructuralType (second, /* keepSugar= */ false );
4222
4215
if (!secondType) return ;
4223
4216
4224
4217
auto inferredSameTypeSource =
0 commit comments