@@ -357,136 +357,6 @@ func testMyEnumWithCaseLabels(_ a : MyEnumWithCaseLabels) {
357
357
}
358
358
359
359
360
-
361
- // "defer"
362
-
363
- func test_defer( _ a : Int ) {
364
-
365
- defer { VoidReturn1 ( ) }
366
- defer { breakContinue ( 1 ) + 42 } // expected-warning {{result of operator '+' is unused}}
367
-
368
- // Ok:
369
- defer { while false { break } }
370
-
371
- // Not ok.
372
- while false { defer { break } } // expected-error {{'break' cannot transfer control out of a defer statement}}
373
- // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{17-22=do}}
374
- defer { return } // expected-error {{'return' cannot transfer control out of a defer statement}}
375
- // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{3-8=do}}
376
- }
377
-
378
- class SomeTestClass {
379
- var x = 42
380
-
381
- func method( ) {
382
- defer { x = 97 } // self. not required here!
383
- // expected-warning@-1 {{'defer' statement at end of scope always executes immediately}}{{5-10=do}}
384
- }
385
- }
386
-
387
- enum DeferThrowError : Error {
388
- case someError
389
- }
390
-
391
- func throwInDefer( ) {
392
- defer { throw DeferThrowError . someError } // expected-error {{errors cannot be thrown out of a defer body}}
393
- print ( " Foo " )
394
- }
395
-
396
- func throwInDeferOK1( ) {
397
- defer {
398
- do {
399
- throw DeferThrowError . someError
400
- } catch { }
401
- }
402
- print ( " Bar " )
403
- }
404
-
405
- func throwInDeferOK2( ) throws {
406
- defer {
407
- do {
408
- throw DeferThrowError . someError
409
- } catch { }
410
- }
411
- print ( " Bar " )
412
- }
413
-
414
- func throwingFuncInDefer1( ) throws {
415
- defer { try throwingFunctionCalledInDefer ( ) } // expected-error {{errors cannot be thrown out of a defer body}}
416
- print ( " Bar " )
417
- }
418
-
419
- func throwingFuncInDefer1a( ) throws {
420
- defer {
421
- do {
422
- try throwingFunctionCalledInDefer ( )
423
- } catch { }
424
- }
425
- print ( " Bar " )
426
- }
427
-
428
- func throwingFuncInDefer2( ) throws {
429
- defer { throwingFunctionCalledInDefer ( ) } // expected-error {{errors cannot be thrown out of a defer body}}
430
- print ( " Bar " )
431
- }
432
-
433
- func throwingFuncInDefer2a( ) throws {
434
- defer {
435
- do {
436
- throwingFunctionCalledInDefer ( )
437
- // expected-error@-1 {{call can throw but is not marked with 'try'}}
438
- // expected-note@-2 {{did you mean to use 'try'?}}
439
- // expected-note@-3 {{did you mean to handle error as optional value?}}
440
- // expected-note@-4 {{did you mean to disable error propagation?}}
441
- } catch { }
442
- }
443
- print ( " Bar " )
444
- }
445
-
446
- func throwingFuncInDefer3( ) {
447
- defer { try throwingFunctionCalledInDefer ( ) } // expected-error {{errors cannot be thrown out of a defer body}}
448
- print ( " Bar " )
449
- }
450
-
451
- func throwingFuncInDefer3a( ) {
452
- defer {
453
- do {
454
- try throwingFunctionCalledInDefer ( )
455
- } catch { }
456
- }
457
- print ( " Bar " )
458
- }
459
-
460
- func throwingFuncInDefer4( ) {
461
- defer { throwingFunctionCalledInDefer ( ) } // expected-error {{errors cannot be thrown out of a defer body}}
462
- print ( " Bar " )
463
- }
464
-
465
- func throwingFuncInDefer4a( ) {
466
- defer {
467
- do {
468
- throwingFunctionCalledInDefer ( )
469
- // expected-error@-1 {{call can throw but is not marked with 'try'}}
470
- // expected-note@-2 {{did you mean to use 'try'?}}
471
- // expected-note@-3 {{did you mean to handle error as optional value?}}
472
- // expected-note@-4 {{did you mean to disable error propagation?}}
473
- } catch { }
474
- }
475
- print ( " Bar " )
476
- }
477
-
478
- func throwingFunctionCalledInDefer( ) throws {
479
- throw DeferThrowError . someError
480
- }
481
-
482
- class SomeDerivedClass : SomeTestClass {
483
- override init ( ) {
484
- defer {
485
- super. init ( ) // expected-error {{initializer chaining ('super.init') cannot be nested in another expression}}
486
- }
487
- }
488
- }
489
-
490
360
func test_guard( _ x : Int , y : Int ? ? , cond : Bool ) {
491
361
492
362
// These are all ok.
0 commit comments