Skip to content

Commit 494e13c

Browse files
committed
GSB: Don't bail out early if some requirements didn't resolve
This doesn't actually matter, except to make the requirement machine minimization cross-checking work on highly-invalid test cases.
1 parent b999cea commit 494e13c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,8 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
39913991
auto protocolSubMap = SubstitutionMap::getProtocolSubstitutions(
39923992
proto, selfType.getDependentType(*this), ProtocolConformanceRef(proto));
39933993

3994+
auto result = ConstraintResult::Resolved;
3995+
39943996
// Use the requirement signature to avoid rewalking the entire protocol. This
39953997
// cannot compute the requirement signature directly, because that may be
39963998
// infinitely recursive: this code is also used to construct it.
@@ -4007,19 +4009,20 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
40074009
auto reqResult = substReq
40084010
? addRequirement(*substReq, innerSource, nullptr)
40094011
: ConstraintResult::Conflicting;
4010-
if (isErrorResult(reqResult)) return reqResult;
4012+
if (isErrorResult(reqResult) && !isErrorResult(result))
4013+
result = reqResult;
40114014
}
40124015

4013-
return ConstraintResult::Resolved;
4016+
return result;
40144017
}
40154018

40164019
if (!onlySameTypeConstraints) {
40174020
// Add all of the inherited protocol requirements, recursively.
40184021
auto inheritedReqResult =
40194022
addInheritedRequirements(proto, selfType.getUnresolvedType(), source,
40204023
nullptr);
4021-
if (isErrorResult(inheritedReqResult))
4022-
return inheritedReqResult;
4024+
if (isErrorResult(inheritedReqResult) && !isErrorResult(inheritedReqResult))
4025+
result = inheritedReqResult;
40234026
}
40244027

40254028
// Add any requirements in the where clause on the protocol.
@@ -4048,7 +4051,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
40484051
getASTContext()),
40494052
innerSource);
40504053

4051-
return ConstraintResult::Resolved;
4054+
return result;
40524055
}
40534056

40544057
// Remaining logic is not relevant in ObjC protocol cases.
@@ -4159,8 +4162,8 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
41594162
auto assocResult =
41604163
addInheritedRequirements(assocTypeDecl, assocType, source,
41614164
/*inferForModule=*/nullptr);
4162-
if (isErrorResult(assocResult))
4163-
return assocResult;
4165+
if (isErrorResult(assocResult) && !isErrorResult(result))
4166+
result = assocResult;
41644167
}
41654168

41664169
// Add requirements from this associated type's where clause.
@@ -4314,7 +4317,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
43144317
}
43154318
}
43164319

4317-
return ConstraintResult::Resolved;
4320+
return result;
43184321
}
43194322

43204323
ConstraintResult GenericSignatureBuilder::addConformanceRequirement(

test/Constraints/associated_types.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ struct UsesSameTypedDefaultDerivedWithoutSatisfyingReqts: SameTypedDefaultDerive
112112
// SR-12199
113113

114114
protocol SR_12199_P1 {
115-
associatedtype Assoc
115+
associatedtype Assoc // expected-note {{'Assoc' declared here}}
116116
}
117117

118118
enum SR_12199_E {}
119119

120120
protocol SR_12199_P2: SR_12199_P1 where Assoc == SR_12199_E {
121121
associatedtype Assoc: SR_12199_E // expected-error {{type 'Self.Assoc' constrained to non-protocol, non-class type 'SR_12199_E'}}
122+
// expected-warning@-1 {{redeclaration of associated type 'Assoc' from protocol 'SR_12199_P1' is better expressed as a 'where' clause on the protocol}}
122123
}

test/IDE/print_ast_tc_decls_errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protocol AssociatedType1 {
192192
// TYREPR: {{^}} associatedtype AssociatedTypeDecl4 : FooNonExistentProtocol, BarNonExistentProtocol{{$}}
193193

194194
associatedtype AssociatedTypeDecl5 : FooClass
195-
// CHECK: {{^}} associatedtype AssociatedTypeDecl5{{$}}
195+
// CHECK: {{^}} associatedtype AssociatedTypeDecl5 : FooClass{{$}}
196196
}
197197

198198
//===---

0 commit comments

Comments
 (0)