mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSBindings] Look through optional types when trying to validate l-valueness of the new bindings
When bindings are picked for particular type variable, right-hand side of the binding might be another type variable wrapped into optional type, when trying to determine if both sides of the binding have the same l-valueness it's imperative to look throught optional type of the right-hand side. Otherwise new binding might be effectively unsolvable. Resolves: rdar://problem/37291371
This commit is contained in:
@@ -447,7 +447,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
|
||||
|
||||
// Make sure we aren't trying to equate type variables with different
|
||||
// lvalue-binding rules.
|
||||
if (auto otherTypeVar = type->getAs<TypeVariableType>()) {
|
||||
if (auto otherTypeVar =
|
||||
type->lookThroughAllOptionalTypes()->getAs<TypeVariableType>()) {
|
||||
if (typeVar->getImpl().canBindToLValue() !=
|
||||
otherTypeVar->getImpl().canBindToLValue())
|
||||
continue;
|
||||
|
||||
21
test/Constraints/rdar37291371.swift
Normal file
21
test/Constraints/rdar37291371.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
|
||||
extension Collection where Element: Numeric {
|
||||
var v: Element {
|
||||
return self.reduce(0, +)
|
||||
}
|
||||
}
|
||||
|
||||
struct R<T> {}
|
||||
func ==<T: Equatable>(lhs: R<T>, rhs: T?) {}
|
||||
|
||||
func foo<T>(_ e: @autoclosure @escaping () throws -> T?) -> R<T> {
|
||||
return R<T>()
|
||||
}
|
||||
|
||||
func bar<T>(_ e: T?) -> R<T> {
|
||||
return R<T>()
|
||||
}
|
||||
|
||||
foo([Double(1.0)].v) == Double(1.0)
|
||||
bar([Double(1.0)].v) == Double(1.0)
|
||||
@@ -5,6 +5,6 @@
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
|
||||
// RUN: not --crash %target-swift-frontend %s -emit-ir
|
||||
// REQUIRES: asserts
|
||||
// RUN: not %target-swift-frontend %s -emit-ir
|
||||
|
||||
nil?as?Int??
|
||||
@@ -5,7 +5,7 @@
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
||||
|
||||
// RUN: not --crash %target-swift-frontend %s -emit-ir
|
||||
// RUN: not %target-swift-frontend %s -emit-ir
|
||||
[.a
|
||||
[Int?as?Int
|
||||
nil?
|
||||
Reference in New Issue
Block a user