@@ -316,6 +316,8 @@ func takesThrowingAutoclosure(_: @autoclosure () throws(MyError) -> Int) {}
316316func takesNonThrowingAutoclosure( _: @autoclosure ( ) throws ( Never ) -> Int ) { }
317317
318318func getInt( ) throws -> Int { 0 }
319+ func getIntAsync( ) async throws -> Int { 0 }
320+ func getBool( ) throws -> Bool { true }
319321
320322func throwingAutoclosures( ) {
321323 takesThrowingAutoclosure ( try getInt ( ) )
@@ -337,3 +339,82 @@ func noThrow() throws(Never) {
337339 // expected-error@-1 {{thrown expression type 'MyError' cannot be converted to error type 'Never'}}
338340 } catch { }
339341}
342+
343+ precedencegroup LowerThanAssignment {
344+ lowerThan : AssignmentPrecedence
345+ }
346+ infix operator ~~~ : LowerThanAssignment
347+ func ~~~ < T, U> ( lhs: T , rhs: U ) { }
348+
349+ func testSequenceExpr( ) async throws ( Never) {
350+ // Make sure the `try` here covers both calls in the ASTScope tree.
351+ try ! getInt ( ) + getInt( ) // expected-warning {{result of operator '+' is unused}}
352+ try ! _ = getInt ( ) + getInt( )
353+ _ = try ! getInt ( ) + getInt( )
354+ _ = try ! getInt ( ) + ( getInt ( ) , 0 ) . 0
355+
356+ _ = try try ! getInt ( ) + getInt( )
357+ // expected-warning@-1 {{no calls to throwing functions occur within 'try' expression}}
358+
359+ _ = await try ! getIntAsync ( ) + getIntAsync( )
360+ // expected-warning@-1 {{'try' must precede 'await'}}
361+
362+ _ = unsafe await try ! getIntAsync ( ) + getIntAsync( )
363+ // expected-warning@-1 {{'try' must precede 'await'}}
364+
365+ _ = try unsafe await try ! getIntAsync ( ) + getIntAsync( )
366+ // expected-warning@-1 {{'try' must precede 'await'}}
367+ // expected-warning@-2 {{no calls to throwing functions occur within 'try' expression}}
368+
369+ try _ = ( try ! getInt ( ) ) + getInt( )
370+ // expected-error@-1:29 {{thrown expression type 'any Error' cannot be converted to error type 'Never'}}
371+
372+ // `try` on the condition covers both branches.
373+ _ = try ! getBool ( ) ? getInt ( ) : getInt ( )
374+
375+ // `try` on "then" branch doesn't cover else.
376+ try _ = getBool ( ) ? try ! getInt ( ) : getInt ( )
377+ // expected-error@-1:11 {{thrown expression type 'any Error' cannot be converted to error type 'Never'}}
378+ // expected-error@-2:39 {{thrown expression type 'any Error' cannot be converted to error type 'Never'}}
379+
380+ // The `try` here covers everything, even if unassignable.
381+ try ! getBool ( ) ? getInt ( ) : getInt ( ) = getInt ( )
382+ // expected-error@-1 {{result of conditional operator '? :' is never mutable}}
383+
384+ // Same here.
385+ try ! getBool ( ) ? getInt ( ) : getInt ( ) ~~~ getInt ( )
386+
387+ try _ = getInt ( ) + try ! getInt ( )
388+ // expected-error@-1 {{thrown expression type 'any Error' cannot be converted to error type 'Never'}}
389+ // expected-error@-2 {{'try!' cannot appear to the right of a non-assignment operator}}
390+
391+ // The ASTScope for `try` here covers both, but isn't covered in the folded
392+ // expression. This is illegal anyway.
393+ _ = 0 + try ! getInt ( ) + getInt( )
394+ // expected-error@-1 {{'try!' cannot appear to the right of a non-assignment operator}}
395+ // expected-error@-2:27 {{call can throw but is not marked with 'try'}}
396+ // expected-note@-3:27 3{{did you mean}}
397+
398+ try _ = 0 + try ! getInt ( ) + getInt( )
399+ // expected-error@-1 {{'try!' cannot appear to the right of a non-assignment operator}}
400+
401+ // The ASTScope for `try` here covers both, but isn't covered in the folded
402+ // expression due `~~~` having a lower precedence than assignment. This is
403+ // illegal anyway.
404+ _ = try ! getInt ( ) ~~~ getInt ( )
405+ // expected-error@-1 {{'try!' following assignment operator does not cover everything to its right}}
406+ // expected-error@-2:25 {{call can throw but is not marked with 'try'}}
407+ // expected-note@-3:25 3{{did you mean}}
408+
409+ try _ = try ! getInt ( ) ~~~ getInt ( )
410+ // expected-error@-1 {{'try!' following assignment operator does not cover everything to its right}}
411+
412+ // Same here.
413+ true ? 0 : try ! getInt ( ) ~~~ getInt ( )
414+ // expected-error@-1 {{'try!' following conditional operator does not cover everything to its right}}
415+ // expected-error@-2:32 {{call can throw but is not marked with 'try'}}
416+ // expected-note@-3:32 3{{did you mean}}
417+
418+ try true ? 0 : try ! getInt ( ) ~~~ getInt ( )
419+ // expected-error@-1 {{'try!' following conditional operator does not cover everything to its right}}
420+ }
0 commit comments