Skip to content

Commit 0fabf82

Browse files
committed
Sema: Fix assert failure with non-representative type variable in contractEdges()
1 parent d9dcc88 commit 0fabf82

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/Sema/ConstraintGraph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,9 @@ bool ConstraintGraph::contractEdges() {
910910
if (!(tyvar1 && tyvar2))
911911
continue;
912912

913+
auto rep1 = CS.getRepresentative(tyvar1);
914+
auto rep2 = CS.getRepresentative(tyvar2);
915+
913916
// If the argument is allowed to bind to `inout`, in general,
914917
// it's invalid to contract the edge between argument and parameter,
915918
// but if we can prove that there are no possible bindings
@@ -919,9 +922,9 @@ bool ConstraintGraph::contractEdges() {
919922
// Such action is valid because argument type variable can
920923
// only get its bindings from related overload, which gives
921924
// us enough information to decided on l-valueness.
922-
if (tyvar1->getImpl().canBindToInOut()) {
925+
if (rep1->getImpl().canBindToInOut()) {
923926
bool isNotContractable = true;
924-
auto bindings = CS.getBindingsFor(tyvar1);
927+
auto bindings = CS.getBindingsFor(rep1);
925928
if (bindings.isViable()) {
926929
// Holes can't be contracted.
927930
if (bindings.isHole())
@@ -949,9 +952,6 @@ bool ConstraintGraph::contractEdges() {
949952
continue;
950953
}
951954

952-
auto rep1 = CS.getRepresentative(tyvar1);
953-
auto rep2 = CS.getRepresentative(tyvar2);
954-
955955
if (CS.isDebugMode()) {
956956
auto indent = CS.solverState ? CS.solverState->getCurrentIndent() : 0;
957957
auto &log = llvm::errs().indent(indent);

validation-test/compiler_crashers/ConstraintSystem-getBindingsFor-4437c5.swift renamed to validation-test/compiler_crashers_fixed/ConstraintSystem-getBindingsFor-4437c5.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","original":"5af4a4fb","signature":"swift::constraints::ConstraintSystem::getBindingsFor(swift::TypeVariableType*)","signatureAssert":"Assertion failed: (typeVar->getImpl().getRepresentative(nullptr) == typeVar && \"not a representative\"), function getBindingsFor"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
struct a {
44
func b(arr: [a]) {
55
arr.compactMap {

0 commit comments

Comments
 (0)