Skip to content

Commit 32a93c7

Browse files
authored
Merge pull request #18260 from rudkx/add-test-for-sr6299
2 parents 1fdad96 + edfe4eb commit 32a93c7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/decl/func/rethrows.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,3 +551,36 @@ public func variadic_rethrows(_ values: Int..., body: (Int) throws -> ()) rethro
551551
public func rdar40472018() {
552552
variadic_rethrows(1, 2) { _ in }
553553
}
554+
555+
556+
// https://bugs.swift.org/browse/SR-6299
557+
// Verify that we do not emit an invalid
558+
// "... can throw but the expression is not marked with 'try'"
559+
// error on the use of the operators.
560+
561+
infix operator <|: infixr0
562+
infix operator |>: infixl1
563+
564+
precedencegroup infixr0 {
565+
associativity: right
566+
}
567+
precedencegroup infixl1 {
568+
associativity: left
569+
higherThan: infixr0
570+
}
571+
572+
func <| <A, B> (f: (A) throws -> B, a: A) rethrows -> B {
573+
return try f(a)
574+
}
575+
func |> <A, B> (a: A, f: (A) -> B) -> B {
576+
return try f(a) // expected-warning {{no calls to throwing functions occur within 'try' expression}}
577+
}
578+
579+
struct Box<A> {
580+
let unbox: A
581+
}
582+
func suchThat<A>(_ x: Box<A>) -> (@escaping (A) -> A) -> Box<A> {
583+
return { f in Box(unbox: f(x.unbox)) }
584+
}
585+
586+
Box(unbox: 1) |> suchThat <| { $0 + 1 } // expected-warning {{result of operator '<|' is unused}}

0 commit comments

Comments
 (0)