Skip to content

[Tests] Add tests for unary operators on tuples #20346

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
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
38 changes: 38 additions & 0 deletions test/decl/func/operator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,41 @@ class C6 {
if x == x && x = x { } // expected-error{{cannot convert value of type 'C6' to expected argument type 'Bool'}}
}
}

prefix operator ∫

prefix func ∫(arg: (Int, Int)) {}

func testPrefixOperatorOnTuple() {

let foo = (1, 2)
_ = ∫foo
_ = (∫)foo
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-warning@-2 {{expression of type '(Int, Int)' is unused}}
_ = (∫)(foo)
_ = ∫(1, 2)
_ = (∫)(1, 2) // expected-error {{operator function '∫' expects a single parameter of type '(Int, Int)'}}
_ = (∫)((1, 2))
}

postfix operator §

postfix func §<T, U>(arg: (T, (U, U), T)) {} // expected-note {{in call to operator '§'}}

func testPostfixOperatorOnTuple<A, B>(a: A, b: B) {

let foo = (a, (b, b), a)
_ = foo§

// FIX-ME: "...could not be inferred" is irrelevant
_ = (§)foo
// expected-error@-1 {{consecutive statements on a line must be separated by ';'}}
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
// expected-warning@-3 {{expression of type '(A, (B, B), A)' is unused}}
_ = (§)(foo)
_ = (a, (b, b), a)§
_ = (§)(a, (b, b), a) // expected-error {{operator function '§' expects a single parameter of type '(T, (U, U), T)'}}
_ = (§)((a, (b, b), a))
_ = (a, ((), (b, (a, a), b)§), a)§
}