@@ -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,33 @@ 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);
3812
- if (!type)
3813
- return Type ();
3813
+ auto type = getStructuralType (concreteDecl, /* keepSugar=*/ true );
3814
3814
3815
- Type parentType;
3816
3815
SubstitutionMap subMap;
3817
3816
if (proto) {
3818
3817
// Substitute in the type of the current PotentialArchetype in
3819
3818
// place of 'Self' here.
3820
- parentType = basePA->getDependentType (builder.getGenericParams ());
3819
+ auto parentType = basePA->getDependentType (builder.getGenericParams ());
3821
3820
3822
3821
subMap = SubstitutionMap::getProtocolSubstitutions (
3823
3822
proto, parentType, ProtocolConformanceRef (proto));
3824
-
3825
- type = type.subst (subMap);
3826
3823
} else {
3827
3824
// Substitute in the superclass type.
3828
3825
auto parentPA = basePA->getEquivalenceClassIfPresent ();
3829
- parentType =
3826
+ auto parentType =
3830
3827
parentPA->concreteType ? parentPA->concreteType : parentPA->superclass ;
3831
3828
auto parentDecl = parentType->getAnyNominal ();
3832
3829
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);
3830
+ subMap = parentType->getContextSubstitutionMap (
3831
+ parentDecl->getParentModule (), dc);
3841
3832
}
3842
3833
3843
- return type;
3834
+ return type. subst (subMap) ;
3844
3835
};
3845
3836
3846
3837
ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass (
@@ -4215,11 +4206,8 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
4215
4206
// An inferred same-type requirement between the two type declarations
4216
4207
// within this protocol or a protocol it inherits.
4217
4208
auto addInferredSameTypeReq = [&](TypeDecl *first, TypeDecl *second) {
4218
- Type firstType = getStructuralType (first);
4219
- if (!firstType) return ;
4220
-
4221
- Type secondType = getStructuralType (second);
4222
- if (!secondType) return ;
4209
+ Type firstType = getStructuralType (first, /* keepSugar=*/ false );
4210
+ Type secondType = getStructuralType (second, /* keepSugar=*/ false );
4223
4211
4224
4212
auto inferredSameTypeSource =
4225
4213
FloatingRequirementSource::viaProtocolRequirement (
0 commit comments