@@ -2377,7 +2377,10 @@ main() {
23772377 x.as_ ('int' ),
23782378 checkPromoted (x, 'int' ),
23792379 checkPromoted (y, 'int' ),
2380- ]).catch_ (body: [checkNotPromoted (x), checkPromoted (y, 'int' )]),
2380+ ]).catch_ (
2381+ type: 'dynamic' ,
2382+ body: [checkNotPromoted (x), checkPromoted (y, 'int' )],
2383+ ),
23812384 ]);
23822385 });
23832386
@@ -2396,6 +2399,7 @@ main() {
23962399 checkPromoted (x, 'int' ),
23972400 getSsaNodes ((nodes) => ssaAfterTry = nodes[x]! ),
23982401 ]).catch_ (
2402+ type: 'dynamic' ,
23992403 body: [
24002404 checkNotPromoted (x),
24012405 getSsaNodes ((nodes) => expect (nodes[x], isNot (ssaAfterTry))),
@@ -2418,7 +2422,7 @@ main() {
24182422 try_ ([
24192423 localFunction ([x.write (expr ('int?' ))]),
24202424 return_ (),
2421- ]).catch_ (body: [x.as_ ('int' ), checkNotPromoted (x)]),
2425+ ]).catch_ (type : 'dynamic' , body: [x.as_ ('int' ), checkNotPromoted (x)]),
24222426 ]);
24232427 });
24242428
@@ -2429,8 +2433,11 @@ main() {
24292433 h.run ([
24302434 declare (x, type: 'int?' , initializer: expr ('int?' )),
24312435 try_ ([])
2432- .catch_ (body: [x.as_ ('int' ), checkPromoted (x, 'int' )])
2433- .catch_ (body: [checkNotPromoted (x)]),
2436+ .catch_ (
2437+ type: 'dynamic' ,
2438+ body: [x.as_ ('int' ), checkPromoted (x, 'int' )],
2439+ )
2440+ .catch_ (type: 'dynamic' , body: [checkNotPromoted (x)]),
24342441 ]);
24352442 },
24362443 );
@@ -2447,6 +2454,54 @@ main() {
24472454 ]);
24482455 });
24492456
2457+ test ('Exception variable is promotable' , () {
2458+ var e = Var ('e' );
2459+ h.run ([
2460+ try_ ([]).catch_ (
2461+ exception: e,
2462+ body: [checkNotPromoted (e), e.as_ ('int' ), checkPromoted (e, 'int' )],
2463+ ),
2464+ ]);
2465+ });
2466+
2467+ test ('Exception variable is promotable' , () {
2468+ var e = Var ('e' );
2469+ h.run ([
2470+ try_ ([]).catch_ (
2471+ type: 'Object' ,
2472+ exception: e,
2473+ body: [
2474+ e.checkType ('Object' ),
2475+ checkNotPromoted (e),
2476+ e.as_ ('String' ),
2477+ checkPromoted (e, 'String' ),
2478+ ],
2479+ ),
2480+ ]);
2481+ });
2482+
2483+ test ('StackTrace variable is promotable' , () {
2484+ TypeRegistry .addInterfaceTypeName ('StackTraceSubtype' );
2485+ h.addSuperInterfaces (
2486+ 'StackTraceSubtype' ,
2487+ (_) => [Type ('StackTrace' ), Type ('Object' )],
2488+ );
2489+ var e = Var ('e' );
2490+ var st = Var ('st' );
2491+ h.run ([
2492+ try_ ([]).catch_ (
2493+ exception: e,
2494+ stackTrace: st,
2495+ body: [
2496+ st.checkType ('StackTrace' ),
2497+ checkNotPromoted (st),
2498+ st.as_ ('StackTraceSubtype' ),
2499+ checkPromoted (st, 'StackTraceSubtype' ),
2500+ ],
2501+ ),
2502+ ]);
2503+ });
2504+
24502505 test (
24512506 'tryCatchStatement_catchEnd() joins catch state with after-try state' ,
24522507 () {
@@ -2460,7 +2515,7 @@ main() {
24602515 try_ ([
24612516 x.as_ ('int' ),
24622517 y.as_ ('int' ),
2463- ]).catch_ (body: [x.as_ ('int' ), z.as_ ('int' )]),
2518+ ]).catch_ (type : 'dynamic' , body: [x.as_ ('int' ), z.as_ ('int' )]),
24642519 // Only x should be promoted, because it's the only variable
24652520 // promoted in both the try body and the catch handler.
24662521 checkPromoted (x, 'int' ), checkNotPromoted (y), checkNotPromoted (z),
@@ -2477,8 +2532,8 @@ main() {
24772532 declare (y, type: 'int?' , initializer: expr ('int?' )),
24782533 declare (z, type: 'int?' , initializer: expr ('int?' )),
24792534 try_ ([return_ ()])
2480- .catch_ (body: [x.as_ ('int' ), y.as_ ('int' )])
2481- .catch_ (body: [x.as_ ('int' ), z.as_ ('int' )]),
2535+ .catch_ (type : 'dynamic' , body: [x.as_ ('int' ), y.as_ ('int' )])
2536+ .catch_ (type : 'dynamic' , body: [x.as_ ('int' ), z.as_ ('int' )]),
24822537 // Only x should be promoted, because it's the only variable promoted
24832538 // in both catch handlers.
24842539 checkPromoted (x, 'int' ), checkNotPromoted (y), checkNotPromoted (z),
0 commit comments