@@ -11600,6 +11600,145 @@ main() {
11600
11600
]);
11601
11601
});
11602
11602
});
11603
+
11604
+ group ('Declared variable pattern with matching non-nullable types' , () {
11605
+ test ('When enabled, guaranteed to match' , () {
11606
+ var x = Var ('x' );
11607
+ h.run ([
11608
+ ifCase (expr ('int' ), x.pattern (type: 'int' ), [
11609
+ checkReachable (true ),
11610
+ ], [
11611
+ checkReachable (false ),
11612
+ ])
11613
+ ]);
11614
+ });
11615
+
11616
+ test ('When disabled, guaranteed to match' , () {
11617
+ // Flow analysis has considered `int x` as guaranteed to match a value
11618
+ // with static type `int` since patterns were added to the language
11619
+ // (even though that was not technically guaranteed to be the case when
11620
+ // running in unsound null safety mode).
11621
+ h.disableSoundFlowAnalysis ();
11622
+ var x = Var ('x' );
11623
+ h.run ([
11624
+ ifCase (expr ('int' ), x.pattern (type: 'int' ), [
11625
+ checkReachable (true ),
11626
+ ], [
11627
+ checkReachable (false ),
11628
+ ])
11629
+ ]);
11630
+ });
11631
+ });
11632
+
11633
+ group ('List pattern' , () {
11634
+ test ('When enabled, guaranteed to match non-nullable list' , () {
11635
+ h.run ([
11636
+ ifCase (expr ('List<int>' ), listPattern ([restPattern ()]), [
11637
+ checkReachable (true ),
11638
+ ], [
11639
+ checkReachable (false ),
11640
+ ])
11641
+ ]);
11642
+ });
11643
+
11644
+ test ('When disabled, guaranteed to match non-nullable list' , () {
11645
+ // Flow analysis has considered a list pattern as guaranteed to match a
11646
+ // value with static type `List` since patterns were added to the
11647
+ // language (even though that was not technically guaranteed to be the
11648
+ // case when running in unsound null safety mode).
11649
+ h.disableSoundFlowAnalysis ();
11650
+ h.run ([
11651
+ ifCase (expr ('List<int>' ), listPattern ([restPattern ()]), [
11652
+ checkReachable (true ),
11653
+ ], [
11654
+ checkReachable (false ),
11655
+ ])
11656
+ ]);
11657
+ });
11658
+ });
11659
+
11660
+ group ('Object pattern with matching non-nullable types' , () {
11661
+ test ('When enabled, guaranteed to match' , () {
11662
+ h.run ([
11663
+ ifCase (expr ('int' ), objectPattern (requiredType: 'int' , fields: []), [
11664
+ checkReachable (true ),
11665
+ ], [
11666
+ checkReachable (false ),
11667
+ ])
11668
+ ]);
11669
+ });
11670
+
11671
+ test ('When disabled, guaranteed to match' , () {
11672
+ // Flow analysis has considered an object pattern as guaranteed to match
11673
+ // a value with a matching static type since patterns were added to the
11674
+ // language (even though that was not technically guaranteed to be the
11675
+ // case when running in unsound null safety mode).
11676
+ h.disableSoundFlowAnalysis ();
11677
+ h.run ([
11678
+ ifCase (expr ('int' ), objectPattern (requiredType: 'int' , fields: []), [
11679
+ checkReachable (true ),
11680
+ ], [
11681
+ checkReachable (false ),
11682
+ ])
11683
+ ]);
11684
+ });
11685
+ });
11686
+
11687
+ group ('Record pattern with matching non-nullable type' , () {
11688
+ test ('When enabled, guaranteed to match' , () {
11689
+ h.run ([
11690
+ ifCase (expr ('(int,)' ),
11691
+ recordPattern ([wildcard (type: 'int' ).recordField ()]), [
11692
+ checkReachable (true ),
11693
+ ], [
11694
+ checkReachable (false ),
11695
+ ])
11696
+ ]);
11697
+ });
11698
+
11699
+ test ('When disabled, guaranteed to match' , () {
11700
+ // Flow analysis has considered a record pattern as guaranteed to match
11701
+ // a value with a matching static type since patterns were added to the
11702
+ // language (even though that was not technically guaranteed to be the
11703
+ // case when running in unsound null safety mode).
11704
+ h.disableSoundFlowAnalysis ();
11705
+ h.run ([
11706
+ ifCase (expr ('(int,)' ),
11707
+ recordPattern ([wildcard (type: 'int' ).recordField ()]), [
11708
+ checkReachable (true ),
11709
+ ], [
11710
+ checkReachable (false ),
11711
+ ])
11712
+ ]);
11713
+ });
11714
+ });
11715
+
11716
+ group ('Wildcard pattern with matching non-nullable types' , () {
11717
+ test ('When enabled, guaranteed to match' , () {
11718
+ h.run ([
11719
+ ifCase (expr ('int' ), wildcard (type: 'int' ), [
11720
+ checkReachable (true ),
11721
+ ], [
11722
+ checkReachable (false ),
11723
+ ])
11724
+ ]);
11725
+ });
11726
+
11727
+ test ('When disabled, guaranteed to match' , () {
11728
+ // Flow analysis has considered `int _` as guaranteed to match a value
11729
+ // with static type `int` since patterns were added to the language
11730
+ // (even though that was not technically guaranteed to be the case when
11731
+ // running in unsound null safety mode).
11732
+ h.disableSoundFlowAnalysis ();
11733
+ h.run ([
11734
+ ifCase (expr ('int' ), wildcard (type: 'int' ), [
11735
+ checkReachable (true ),
11736
+ ], [
11737
+ checkReachable (false ),
11738
+ ])
11739
+ ]);
11740
+ });
11741
+ });
11603
11742
});
11604
11743
}
11605
11744
0 commit comments