Skip to content

[4.1][CSBindings] Look through optional types when trying to validate l-va… #14490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Sema/CSBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,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->lookThroughAllAnyOptionalTypes()->getAs<TypeVariableType>()) {
if (typeVar->getImpl().canBindToLValue() !=
otherTypeVar->getImpl().canBindToLValue())
continue;
Expand Down
21 changes: 21 additions & 0 deletions test/Constraints/rdar37291371.swift
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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??
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This source file is part of the Swift.org open source project
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not %target-swift-frontend %s -emit-ir
[.a
[Int?as?Int
nil?