Skip to content

Commit 1a0801a

Browse files
authored
Merge pull request #37699 from xedin/rdar-78623338
[ConstraintSystem] Simplify relational constraints with the same depe…
2 parents c1fce93 + 1c3d685 commit 1a0801a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5182,6 +5182,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
51825182
llvm_unreachable("type variables should have already been handled by now");
51835183

51845184
case TypeKind::DependentMember: {
5185+
// If types are identical, let's consider this constraint solved
5186+
// even though they are dependent members, they would be resolved
5187+
// to the same concrete type.
5188+
if (desugar1->isEqual(desugar2))
5189+
return getTypeMatchSuccess();
5190+
51855191
// If one of the dependent member types has no type variables,
51865192
// this comparison is effectively illformed, because dependent
51875193
// member couldn't be simplified down to the actual type, and

test/Constraints/generics.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,3 +870,19 @@ func test_ternary_operator_with_regular_conformance_to_literal_protocol() {
870870

871871
bug(true ? test(0) : test(42)) // Ok - type is `CGFloat` for 0 and 42
872872
}
873+
874+
// rdar://78623338 - crash due to leftover inactive constraints
875+
func rdar78623338() {
876+
func any<T : Sequence>(_ sequence: T) -> AnySequence<T.Element> {
877+
// expected-note@-1 {{required by local function 'any' where 'T' = '() -> ReversedCollection<(ClosedRange<Int>)>'}}
878+
AnySequence(sequence.makeIterator)
879+
}
880+
881+
let _ = [
882+
any(0...3),
883+
// TODO: It should be possible to suggest making a call to `reserved` here but we don't have machinery to do so
884+
// at the moment because there is no way to go from a requirement to the underlying argument/parameter location.
885+
any((1...3).reversed) // expected-error {{type '() -> ReversedCollection<(ClosedRange<Int>)>' cannot conform to 'Sequence'}}
886+
// expected-note@-1 {{only concrete types such as structs, enums and classes can conform to protocols}}
887+
]
888+
}

0 commit comments

Comments
 (0)