Skip to content

Commit 3b795ac

Browse files
committed
RequirementMachine: Fix crash when type parameter is fixed to an existential
This is a crash-on-invalid -- the user probably meant to write "T.Value: Collection" rather than "T.Value == Collection". Fixes rdar://151479861.
1 parent e1e9f04 commit 3b795ac

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/AST/RequirementMachine/ConcreteContraction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ ConcreteContraction::substTypeParameterRec(Type type, Position position) const {
321321
return std::nullopt;
322322
}
323323

324+
auto *nominalDecl = (*substBaseType)->getAnyNominal();
325+
if (!nominalDecl || isa<ProtocolDecl>(nominalDecl))
326+
return std::nullopt;
327+
324328
// Substitute the base type into the member type.
325329
auto *dc = typeDecl->getDeclContext();
326330
auto subMap = (*substBaseType)->getContextSubstitutionMap(dc);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P1 {
4+
associatedtype Value
5+
}
6+
7+
protocol P2 {
8+
typealias A = Int
9+
}
10+
11+
struct G<T: P1> where T.Value == any Collection, T.Value.Element: P2 {}
12+
// expected-error@-1 {{cannot access associated type 'Element' from 'any Collection'; use a concrete type or generic parameter base instead}}
13+

0 commit comments

Comments
 (0)