Skip to content

Commit 11ba7e0

Browse files
committed
[CSSimplify] When trying to simplify bind with error type fail gracefully
Since member lookup doesn't check requirements it might sometimes return types which are not visible in the current context e.g. typealias defined in constrained extension, substitution of which might produce error type for base, so assignement should thead lightly and just fail if it encounters such types. Resolves: rdar://problem/39931339 Resolves: SR-5013
1 parent 29ae088 commit 11ba7e0

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,16 @@ ConstraintSystem::matchTypesBindTypeVar(
14881488
if (!isBindable(typeVar, type))
14891489
return formUnsolvedResult();
14901490

1491+
// Since member lookup doesn't check requirements
1492+
// it might sometimes return types which are not
1493+
// visible in the current context e.g. typealias
1494+
// defined in constrained extension, substitution
1495+
// of which might produce error type for base, so
1496+
// assignement should thead lightly and just fail
1497+
// if it encounters such types.
1498+
if (type->hasError())
1499+
return getTypeMatchFailure(locator);
1500+
14911501
// Equal constraints allow mixed LValue/RValue bindings, but
14921502
// if we bind a type to a type variable that can bind to
14931503
// LValues as part of simplifying the Equal constraint we may

validation-test/compiler_crashers_2/0130-sr5013.swift renamed to validation-test/compiler_crashers_2_fixed/0130-sr5013.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: not --crash %target-swift-frontend -typecheck %s
2-
// REQUIRES: asserts
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
33

44
protocol A {
55
associatedtype B
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
protocol P0 {
4+
associatedtype A
5+
}
6+
7+
protocol P1 {
8+
associatedtype B : P3 = S0<S2>
9+
associatedtype C = ()
10+
}
11+
12+
protocol P2 {
13+
associatedtype D : P1
14+
associatedtype E : P3 = S0<S2>
15+
}
16+
17+
protocol P3 : P0 where A : P2 {}
18+
19+
struct S0<T> : P0 {
20+
typealias A = T
21+
}
22+
23+
extension S0 : P3 where T : P2 {}
24+
25+
struct S2 : P2 {
26+
struct D : P1 {
27+
let value: S2
28+
}
29+
}
30+
31+
extension P1 where C : P2 {
32+
typealias B = C.E
33+
}
34+
35+
extension P3 {
36+
func foo() {
37+
_ = A.D.B.self
38+
}
39+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// REQUIRES: asserts
9-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
9+
// RUN: not %target-swift-frontend %s -emit-ir
1010
protocol A{{}protocol a{extension{class a<a{let d=a(class a<P

validation-test/compiler_crashers/28828-unreachable-executed-at-swift-lib-ast-type-cpp-3237.swift renamed to validation-test/compiler_crashers_fixed/28828-unreachable-executed-at-swift-lib-ast-type-cpp-3237.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
class a<a{class a{extension{protocol P{class a:a{func a:Self.a

0 commit comments

Comments
 (0)