Skip to content

Commit a091d4f

Browse files
authored
Merge pull request #32666 from slavapestov/same-type-requirement-assert
AST: Add more asserts for same-type constraints in generic signatures
2 parents ed1dc0f + 844ab50 commit a091d4f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,27 @@ CanGenericSignature::getCanonical(TypeArrayView<GenericTypeParamType> params,
236236
"Left-hand side is not canonical");
237237
break;
238238

239-
case RequirementKind::SameType:
240-
assert(reqt.getFirstType()->isTypeParameter() &&
241-
"Left-hand side must be a type parameter");
239+
case RequirementKind::SameType: {
240+
auto isCanonicalAnchor = [&](Type type) {
241+
if (auto *dmt = type->getAs<DependentMemberType>())
242+
return canSig->isCanonicalTypeInContext(dmt->getBase());
243+
return type->is<GenericTypeParamType>();
244+
};
245+
246+
auto firstType = reqt.getFirstType();
247+
auto secondType = reqt.getSecondType();
248+
assert(isCanonicalAnchor(firstType));
249+
242250
if (reqt.getSecondType()->isTypeParameter()) {
243-
assert(compareDependentTypes(reqt.getFirstType(), reqt.getSecondType())
244-
< 0 &&
251+
assert(isCanonicalAnchor(secondType));
252+
assert(compareDependentTypes(firstType, secondType) < 0 &&
245253
"Out-of-order type parameters in same-type constraint");
246254
} else {
247-
assert(canSig->isCanonicalTypeInContext(reqt.getSecondType()) &&
255+
assert(canSig->isCanonicalTypeInContext(secondType) &&
248256
"Concrete same-type isn't canonical in its own context");
249257
}
250258
break;
259+
}
251260

252261
case RequirementKind::Conformance:
253262
assert(reqt.getFirstType()->isTypeParameter() &&

test/Prototypes/BigInt.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
// REQUIRES: executable_test
1717
// REQUIRES: CPU=x86_64
1818

19+
// rdar://problem/65015626
20+
// XFAIL: asserts
21+
1922
import StdlibUnittest
2023
#if canImport(Darwin)
2124
import Darwin

0 commit comments

Comments
 (0)