Skip to content

Commit 9564de7

Browse files
authored
Merge pull request #14490 from xedin/rdar-37291371-4.1
[4.1][CSBindings] Look through optional types when trying to validate l-va…
2 parents 5cbecbd + cdc2902 commit 9564de7

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
462462

463463
// Make sure we aren't trying to equate type variables with different
464464
// lvalue-binding rules.
465-
if (auto otherTypeVar = type->getAs<TypeVariableType>()) {
465+
if (auto otherTypeVar =
466+
type->lookThroughAllAnyOptionalTypes()->getAs<TypeVariableType>()) {
466467
if (typeVar->getImpl().canBindToLValue() !=
467468
otherTypeVar->getImpl().canBindToLValue())
468469
continue;

test/Constraints/rdar37291371.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
extension Collection where Element: Numeric {
4+
var v: Element {
5+
return self.reduce(0, +)
6+
}
7+
}
8+
9+
struct R<T> {}
10+
func ==<T: Equatable>(lhs: R<T>, rhs: T?) {}
11+
12+
func foo<T>(_ e: @autoclosure @escaping () throws -> T?) -> R<T> {
13+
return R<T>()
14+
}
15+
16+
func bar<T>(_ e: T?) -> R<T> {
17+
return R<T>()
18+
}
19+
20+
foo([Double(1.0)].v) == Double(1.0)
21+
bar([Double(1.0)].v) == Double(1.0)

validation-test/compiler_crashers/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift renamed to validation-test/compiler_crashers_fixed/28625-destoptionals-size-destextraoptionals-srcoptionals-size.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
9-
// REQUIRES: asserts
8+
// RUN: not %target-swift-frontend %s -emit-ir
9+
1010
nil?as?Int??
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This source file is part of the Swift.org open source project
2+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
3+
// Licensed under Apache License v2.0 with Runtime Library Exception
4+
//
5+
// See https://swift.org/LICENSE.txt for license information
6+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
7+
8+
// RUN: not %target-swift-frontend %s -emit-ir
9+
[.a
10+
[Int?as?Int
11+
nil?

0 commit comments

Comments
 (0)