Skip to content

Commit f3f2ea6

Browse files
committed
AST: Skip requirement checks in IsBindableVisitor::visitBoundGenericType() if substituted type is an interface type
IsBindableVisitor is part of TypeBase::substituteBindingsTo(), which is used for two things: - Checking if one contextual type is a proper substitution of another contextual type, used in the solver - To compute the substituted generic signature when lowering a SIL function type In the first case, we're interested in knowing if the substitution succeeds or fails. In the second case, we know the substitution is correct by construction, and we're trying to recover the generic requirements. In the second case though, the substituted type might be an interface type, and if the interface type is constrained to a concrete type in the original type's generic signature, we would conclude that the substitution should fail. This is incorrect, and we should just skip the check if the substituted type is an interface type -- we do not have enough information to know if it succeeds, and instead we must assume it does because otherwise the substituted type passed in to type lowering must be incorrect. Fixes https://bugs.swift.org/browse/SR-13849.
1 parent b70c967 commit f3f2ea6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/AST/Type.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,12 @@ class IsBindableVisitor
20952095
if (req.getKind() != RequirementKind::Conformance) continue;
20962096

20972097
auto canTy = req.getFirstType()->getCanonicalType();
2098+
2099+
// If the substituted type is an interface type, we can't verify the
2100+
// generic requirements.
2101+
if (canTy.subst(substSubMap)->isTypeParameter())
2102+
continue;
2103+
20982104
auto *proto = req.getProtocolDecl();
20992105
auto origConf = origSubMap.lookupConformance(canTy, proto);
21002106
auto substConf = substSubMap.lookupConformance(canTy, proto);

validation-test/compiler_crashers_2/sr13849.swift renamed to validation-test/compiler_crashers_2_fixed/sr13849.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend -emit-ir %s
1+
// RUN: %target-swift-frontend -emit-ir %s
22

33
public protocol Prot {
44
associatedtype T

0 commit comments

Comments
 (0)