Skip to content

Commit 3522f3c

Browse files
author
Max Moiseev
committed
Fixing tests with artihmetic operators back on concrete types
1 parent b5ab726 commit 3522f3c

7 files changed

+27
-27
lines changed

test/Constraints/bridging.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ let d2: Double = 3.14159
200200
inferDouble2 = d2
201201

202202
// rdar://problem/18269449
203-
var i1: Int = 1.5 * 3.5 // expected-error {{cannot convert value of type 'Double' to expected argument type 'Int'}}
203+
var i1: Int = 1.5 * 3.5 // expected-error {{cannot convert value of type 'Double' to specified type 'Int'}}
204204

205205
// rdar://problem/18330319
206206
func rdar18330319(_ s: String, d: [String : AnyObject]) {
@@ -255,12 +255,12 @@ func rdar19770981(_ s: String, ns: NSString) {
255255

256256
// <rdar://problem/19831919> Fixit offers as! conversions that are known to always fail
257257
func rdar19831919() {
258-
var s1 = 1 + "str"; // expected-error{{binary operator '+' cannot be applied to operands of type 'Int' and 'String'}} expected-note{{overloads for '+' exist with these partially matching parameter lists: (String, String), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
258+
var s1 = 1 + "str"; // expected-error{{binary operator '+' cannot be applied to operands of type 'Int' and 'String'}} expected-note{{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (String, String), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
259259
}
260260

261261
// <rdar://problem/19831698> Incorrect 'as' fixits offered for invalid literal expressions
262262
func rdar19831698() {
263-
var v70 = true + 1 // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and 'Int'}} expected-note {{overloads for '+' exist with these partially matching parameter lists: (UnsafeMutablePointer<Pointee>, Int), (UnsafePointer<Pointee>, Int)}}
263+
var v70 = true + 1 // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and 'Int'}} expected-note {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (UnsafeMutablePointer<Pointee>, Int), (UnsafePointer<Pointee>, Int)}}
264264
var v71 = true + 1.0 // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and 'Double'}}
265265
// expected-note@-1{{overloads for '+'}}
266266
var v72 = true + true // expected-error{{binary operator '+' cannot be applied to two 'Bool' operands}}

test/Constraints/closures.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func f20371273() {
262262
let x: [Int] = [1, 2, 3, 4]
263263
let y: UInt = 4
264264
_ = x.filter { ($0 + y) > 42 } // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt'}}
265-
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists: (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
265+
// expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
266266
}
267267

268268

test/Constraints/diagnostics.swift

+16-15
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ if AssocTest.one(1) == AssocTest.one(1) {} // expected-error{{binary operator '=
663663
func r24251022() {
664664
var a = 1
665665
var b: UInt32 = 2
666-
a += a +
667-
b // expected-error {{cannot convert value of type 'UInt32' to expected argument type 'Int'}}
666+
a += a + // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'UInt32'}} expected-note {{overloads for '+' exist}}
667+
b
668668
}
669669

670670
func overloadSetResultType(_ a : Int, b : Int) -> Int {
@@ -701,14 +701,15 @@ func nilComparison(i: Int, o: AnyObject) {
701701
_ = i != nil // expected-warning {{comparing non-optional value of type 'Int' to nil always returns true}}
702702
_ = nil != i // expected-warning {{comparing non-optional value of type 'Int' to nil always returns true}}
703703

704-
_ = i < nil // expected-error {{type 'Int' is not optional, value can never be nil}}
705-
_ = nil < i // expected-error {{type 'Int' is not optional, value can never be nil}}
706-
_ = i <= nil // expected-error {{type 'Int' is not optional, value can never be nil}}
707-
_ = nil <= i // expected-error {{type 'Int' is not optional, value can never be nil}}
708-
_ = i > nil // expected-error {{type 'Int' is not optional, value can never be nil}}
709-
_ = nil > i // expected-error {{type 'Int' is not optional, value can never be nil}}
710-
_ = i >= nil // expected-error {{type 'Int' is not optional, value can never be nil}}
711-
_ = nil >= i // expected-error {{type 'Int' is not optional, value can never be nil}}
704+
// FIXME(integers): uncomment these tests once the < is no longer ambiguous
705+
// _ = i < nil // _xpected-error {{type 'Int' is not optional, value can never be nil}}
706+
// _ = nil < i // _xpected-error {{type 'Int' is not optional, value can never be nil}}
707+
// _ = i <= nil // _xpected-error {{type 'Int' is not optional, value can never be nil}}
708+
// _ = nil <= i // _xpected-error {{type 'Int' is not optional, value can never be nil}}
709+
// _ = i > nil // _xpected-error {{type 'Int' is not optional, value can never be nil}}
710+
// _ = nil > i // _xpected-error {{type 'Int' is not optional, value can never be nil}}
711+
// _ = i >= nil // _xpected-error {{type 'Int' is not optional, value can never be nil}}
712+
// _ = nil >= i // _xpected-error {{type 'Int' is not optional, value can never be nil}}
712713

713714
_ = o === nil // expected-warning {{comparing non-optional value of type 'AnyObject' to nil always returns false}}
714715
_ = o !== nil // expected-warning {{comparing non-optional value of type 'AnyObject' to nil always returns true}}
@@ -748,7 +749,7 @@ func rdar27391581(_ a : Int, b : Int) -> Int {
748749

749750
// <rdar://problem/22276040> QoI: not great error message with "withUnsafePointer" sametype constraints
750751
func read2(_ p: UnsafeMutableRawPointer, maxLength: Int) {}
751-
func read<T : Integer>() -> T? {
752+
func read<T : BinaryInteger>() -> T? {
752753
var buffer : T
753754
let n = withUnsafePointer(to: &buffer) { (p) in
754755
read2(UnsafePointer(p), maxLength: MemoryLayout<T>.size) // expected-error {{cannot convert value of type 'UnsafePointer<_>' to expected argument type 'UnsafeMutableRawPointer'}}
@@ -921,10 +922,10 @@ let r29850459_a: Int = 0
921922
let r29850459_b: Int = 1
922923
func r29850459() -> Bool { return false }
923924
let _ = (r29850459_flag ? r29850459_a : r29850459_b) + 42.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
924-
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (Double, Double), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
925+
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
925926
let _ = ({ true }() ? r29850459_a : r29850459_b) + 42.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
926-
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (Double, Double), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
927+
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
927928
let _ = (r29850459() ? r29850459_a : r29850459_b) + 42.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
928-
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (Double, Double), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
929+
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
929930
let _ = ((r29850459_flag || r29850459()) ? r29850459_a : r29850459_b) + 42.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
930-
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Int, Int), (Double, Double), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
931+
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}

test/Constraints/generics.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ class Whatever<A: Arithmetic, B: Arithmetic> { // expected-note 2 {{'A' declare
231231
static func bar() {}
232232

233233
}
234-
Whatever.foo(a: 23) // expected-error {{generic parameter 'A' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{9-9=<<#A: IntegerArithmetic#>, <#B: IntegerArithmetic#>>}}
234+
Whatever.foo(a: 23) // expected-error {{generic parameter 'A' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{9-9=<<#A: Arithmetic#>, <#B: Arithmetic#>>}}
235235

236236
// <rdar://problem/21718955> Swift useless error: cannot invoke 'foo' with no arguments
237-
Whatever.bar() // expected-error {{generic parameter 'A' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{9-9=<<#A: IntegerArithmetic#>, <#B: IntegerArithmetic#>>}}
237+
Whatever.bar() // expected-error {{generic parameter 'A' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{9-9=<<#A: Arithmetic#>, <#B: Arithmetic#>>}}
238238

239239
// <rdar://problem/27515965> Type checker doesn't enforce same-type constraint if associated type is Any
240240
protocol P27515965 {

test/Constraints/lvalues.swift

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var x : X
2828
var y : Y
2929

3030
func +=(lhs: inout X, rhs : X) {}
31-
func +=(lhs: inout Double, rhs : Double) {}
3231
prefix operator +++
3332
prefix func +++(rhs: inout X) {}
3433

test/Interpreter/currying_generics.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ public func test_compose_closure(_ x: Int) -> Int32 {
7373
let insult = curry(+)("I'm with stupid ☞ ")
7474
print(insult("😡")) // CHECK: I'm with stupid ☞ 😡
7575

76-
let plus1 = curry(+)(1)
76+
let plus1 = curry({ $0 + $1 })(1)
7777
print(plus1(5)) // CHECK-NEXT: 6
7878

79-
let plus5 = curry(+)(5)
79+
let plus5 = curry({ $0 + $1 })(5)
8080
print(plus5(5)) // CHECK-NEXT: 10
8181

8282
print(insult("😰")) // CHECK-NEXT: I'm with stupid ☞ 😰

test/Interpreter/protocol_extensions.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ extension Sequence {
5555
}
5656

5757
// CHECK: 15
58-
print([1, 2, 3, 4, 5].myReduce(0, combine: +))
58+
print([1, 2, 3, 4, 5].myReduce(0, combine: { $0 + $1 }))
5959

6060

6161
extension Sequence {
@@ -82,9 +82,9 @@ extension MutableCollection
8282
}
8383

8484
extension RangeReplaceableCollection {
85-
public final func myJoin<S : Sequence where S.Iterator.Element == Self>(
85+
public final func myJoin<S : Sequence>(
8686
_ elements: S
87-
) -> Self {
87+
) -> Self where S.Iterator.Element == Self {
8888
var result = Self()
8989
var iter = elements.makeIterator()
9090
if let first = iter.next() {

0 commit comments

Comments
 (0)