Merge pull request #14482 from xedin/rdar-37291371

[CSBindings] Look through optional types when trying to validate l-va…
diff --git a/lib/Sema/CSBindings.cpp b/lib/Sema/CSBindings.cpp
index e1b1751..6c88e28 100644
--- a/lib/Sema/CSBindings.cpp
+++ b/lib/Sema/CSBindings.cpp
@@ -447,7 +447,8 @@
 
     // 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;
diff --git a/test/Constraints/rdar37291371.swift b/test/Constraints/rdar37291371.swift
new file mode 100644
index 0000000..97385a5
--- /dev/null
+++ b/test/Constraints/rdar37291371.swift
@@ -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)
diff --git a/validation-test/compiler_crashers/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift b/validation-test/compiler_crashers_fixed/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift
similarity index 82%
rename from validation-test/compiler_crashers/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift
rename to validation-test/compiler_crashers_fixed/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift
index beabdb0..4467ebf 100644
--- a/validation-test/compiler_crashers/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift
+++ b/validation-test/compiler_crashers_fixed/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift
@@ -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??
diff --git a/validation-test/compiler_crashers/28866-unreachable-executed-at-swift-include-swift-ast-cantypevisitor-h-41.swift b/validation-test/compiler_crashers_fixed/28866-unreachable-executed-at-swift-include-swift-ast-cantypevisitor-h-41.swift
similarity index 86%
rename from validation-test/compiler_crashers/28866-unreachable-executed-at-swift-include-swift-ast-cantypevisitor-h-41.swift
rename to validation-test/compiler_crashers_fixed/28866-unreachable-executed-at-swift-include-swift-ast-cantypevisitor-h-41.swift
index 5c7f26e..d9a82dc 100644
--- a/validation-test/compiler_crashers/28866-unreachable-executed-at-swift-include-swift-ast-cantypevisitor-h-41.swift
+++ b/validation-test/compiler_crashers_fixed/28866-unreachable-executed-at-swift-include-swift-ast-cantypevisitor-h-41.swift
@@ -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?