Skip to content

Commit 555414a

Browse files
committed
[Tests] Add tests for unary operators on tuples
1 parent d1089c3 commit 555414a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/decl/func/operator.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,41 @@ class C6 {
359359
if x == x && x = x { } // expected-error{{cannot convert value of type 'C6' to expected argument type 'Bool'}}
360360
}
361361
}
362+
363+
prefix operator
364+
365+
prefix func (arg: (Int, Int)) {}
366+
367+
func testPrefixOperatorOnTuple() {
368+
369+
let foo = (1, 2)
370+
_ = foo
371+
_ = ()foo
372+
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
373+
// expected-warning@-2 {{expression of type '(Int, Int)' is unused}}
374+
_ = ()(foo)
375+
_ = (1, 2)
376+
_ = ()(1, 2) // expected-error {{operator function '∫' expects a single parameter of type '(Int, Int)'}}
377+
_ = ()((1, 2))
378+
}
379+
380+
postfix operator §
381+
382+
postfix func §<T, U>(arg: (T, (U, U), T)) {} // expected-note {{in call to operator '§'}}
383+
384+
func testPostfixOperatorOnTuple<A, B>(a: A, b: B) {
385+
386+
let foo = (a, (b, b), a)
387+
_ = foo§
388+
389+
// FIX-ME: "...could not be inferred" is irrelevant
390+
_ = (§)foo
391+
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
392+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
393+
// expected-warning@-3 {{expression of type '(A, (B, B), A)' is unused}}
394+
_ = (§)(foo)
395+
_ = (a, (b, b), a)§
396+
_ = (§)(a, (b, b), a) // expected-error {{operator function '§' expects a single parameter of type '(T, (U, U), T)'}}
397+
_ = (§)((a, (b, b), a))
398+
_ = (a, ((), (b, (a, a), b)§), a)§
399+
}

0 commit comments

Comments
 (0)