Skip to content

Commit 353b4cc

Browse files
committed
Sema: Solve Bind constraints involving to two variables of different lvalue-ness
The restriction here only applies to Equal constraints. Fixes <rdar://problem/45511838>, <https://bugs.swift.org/browse/SR-9068>.
1 parent 3387154 commit 353b4cc

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
17301730

17311731
// If exactly one of the type variables can bind to an lvalue, we
17321732
// can't merge these two type variables.
1733-
if (rep1->getImpl().canBindToLValue()
1733+
if (kind == ConstraintKind::Equal &&
1734+
rep1->getImpl().canBindToLValue()
17341735
!= rep2->getImpl().canBindToLValue())
17351736
return formUnsolvedResult();
17361737

test/Constraints/generics.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func generic_metatypes<T : SomeProtocol>(_ x: T)
5252
}
5353

5454
// Inferring a variable's type from a call to a generic.
55-
struct Pair<T, U> { } // expected-note 4 {{'T' declared as parameter to type 'Pair'}} expected-note {{'U' declared as parameter to type 'Pair'}}
55+
struct Pair<T, U> { } // expected-note 3 {{'T' declared as parameter to type 'Pair'}} expected-note 2 {{'U' declared as parameter to type 'Pair'}}
5656

5757
func pair<T, U>(_ x: T, _ y: U) -> Pair<T, U> { }
5858

@@ -364,7 +364,7 @@ func testFixItCasting(x: Any) {
364364

365365
func testFixItContextualKnowledge() {
366366
// FIXME: These could propagate backwards.
367-
let _: Int = Pair().first // expected-error {{generic parameter 'T' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{20-20=<Any, Any>}}
367+
let _: Int = Pair().first // expected-error {{generic parameter 'U' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{20-20=<Any, Any>}}
368368
let _: Int = Pair().second // expected-error {{generic parameter 'T' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{20-20=<Any, Any>}}
369369
}
370370

@@ -622,7 +622,7 @@ func rdar40537858() {
622622
let _: E = .bar([s]) // expected-error {{enum case 'bar' requires that 'S' conform to 'P'}}
623623
}
624624

625-
// SR-8934
625+
// https://bugs.swift.org/browse/SR-8934
626626
struct BottleLayout {
627627
let count : Int
628628
}
@@ -631,3 +631,10 @@ let layout = BottleLayout(count:1)
631631
let ix = arr.firstIndex(of:layout) // expected-error {{argument type 'BottleLayout' does not conform to expected type 'Equatable'}}
632632

633633
let _: () -> UInt8 = { .init("a" as Unicode.Scalar) } // expected-error {{initializer 'init(_:)' requires that 'Unicode.Scalar' conform to 'BinaryInteger'}}
634+
635+
// https://bugs.swift.org/browse/SR-9068
636+
func compare<C: Collection, Key: Hashable, Value: Equatable>(c: C)
637+
-> Bool where C.Element == (key: Key, value: Value)
638+
{
639+
_ = Dictionary(uniqueKeysWithValues: Array(c))
640+
}

0 commit comments

Comments
 (0)