Skip to content

Commit 974e64a

Browse files
authored
Merge pull request #37767 from xedin/rdar-78623338-5.5
[5.5][ConstraintSystem] Simplify relational constraints with the same depe…
2 parents ce7fc16 + ef5c4db commit 974e64a

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
@@ -5185,6 +5185,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
51855185
llvm_unreachable("type variables should have already been handled by now");
51865186

51875187
case TypeKind::DependentMember: {
5188+
// If types are identical, let's consider this constraint solved
5189+
// even though they are dependent members, they would be resolved
5190+
// to the same concrete type.
5191+
if (desugar1->isEqual(desugar2))
5192+
return getTypeMatchSuccess();
5193+
51885194
// If one of the dependent member types has no type variables,
51895195
// this comparison is effectively illformed, because dependent
51905196
// 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
@@ -858,3 +858,19 @@ func rdar56212087() {
858858

859859
setValue(foo("", ""), forKey: "") // Ok (T is inferred as a `String` instead of `Any?`)
860860
}
861+
862+
// rdar://78623338 - crash due to leftover inactive constraints
863+
func rdar78623338() {
864+
func any<T : Sequence>(_ sequence: T) -> AnySequence<T.Element> {
865+
// expected-note@-1 {{required by local function 'any' where 'T' = '() -> ReversedCollection<(ClosedRange<Int>)>'}}
866+
AnySequence(sequence.makeIterator)
867+
}
868+
869+
let _ = [
870+
any(0...3),
871+
// TODO: It should be possible to suggest making a call to `reserved` here but we don't have machinery to do so
872+
// at the moment because there is no way to go from a requirement to the underlying argument/parameter location.
873+
any((1...3).reversed) // expected-error {{type '() -> ReversedCollection<(ClosedRange<Int>)>' cannot conform to 'Sequence'}}
874+
// expected-note@-1 {{only concrete types such as structs, enums and classes can conform to protocols}}
875+
]
876+
}

0 commit comments

Comments
 (0)