Skip to content

Commit 239bfac

Browse files
committed
[ConstraintSystem] Account for situations when witness for associated type is null
In some circularity cases `getAssociatedType` would produce a `Type()`, we need to account for that in `TypeSimplifier` to avoid crashing.
1 parent e33001a commit 239bfac

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4224,7 +4224,7 @@ struct TypeSimplifier {
42244224

42254225
auto result = conformance.getAssociatedType(
42264226
lookupBaseType, assocType->getDeclaredInterfaceType());
4227-
if (!result->hasError())
4227+
if (result && !result->hasError())
42284228
return result;
42294229
}
42304230

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
public protocol P1 {
4+
associatedtype A
5+
6+
init(a: A)
7+
}
8+
9+
public protocol P2: P1 {
10+
associatedtype B
11+
12+
init()
13+
}
14+
15+
extension P2 where A == B {
16+
public init() { fatalError() }
17+
public init(a: B) { fatalError() }
18+
}
19+
20+
public protocol P3: P2 {
21+
associatedtype B = Self
22+
23+
static var y: B { get }
24+
}
25+
26+
public struct S: P3 {
27+
public static let x = S(c: 1)
28+
public static let y = S(c: 2)
29+
30+
public init(c: Int) {}
31+
}

0 commit comments

Comments
 (0)