@@ -524,6 +524,20 @@ impl Pattern {
524
524
Some ( new)
525
525
}
526
526
527
+ pub fn is_normalized ( & self ) -> bool {
528
+ match self {
529
+ Pattern :: Constant ( _) => true ,
530
+ Pattern :: Dynamic => true ,
531
+ Pattern :: Alternatives ( list) => list
532
+ . iter ( )
533
+ . all ( |alt| !matches ! ( alt, Pattern :: Alternatives ( _) ) && alt. is_normalized ( ) ) ,
534
+ Pattern :: Concatenation ( list) => list. iter ( ) . all ( |alt| {
535
+ !matches ! ( alt, Pattern :: Alternatives ( _) | Pattern :: Concatenation ( _) )
536
+ && alt. is_normalized ( )
537
+ } ) ,
538
+ }
539
+ }
540
+
527
541
/// Order into Alternatives -> Concatenation -> Constant/Dynamic
528
542
/// Merge when possible
529
543
pub fn normalize ( & mut self ) {
@@ -669,6 +683,7 @@ impl Pattern {
669
683
}
670
684
}
671
685
}
686
+ debug_assert ! ( self . is_normalized( ) ) ;
672
687
}
673
688
674
689
pub fn filter_could_match ( & self , value : & str ) -> Option < Pattern > {
@@ -1366,6 +1381,10 @@ pub async fn read_matches(
1366
1381
force_in_lookup_dir : bool ,
1367
1382
pattern : Vc < Pattern > ,
1368
1383
) -> Result < Vc < PatternMatches > > {
1384
+ #[ cfg( debug_assertions) ]
1385
+ if !pattern. await ?. is_normalized ( ) {
1386
+ panic ! ( "Pattern must be normalized {:?}" , pattern. await ?) ;
1387
+ }
1369
1388
let mut prefix = prefix. to_string ( ) ;
1370
1389
let pat = pattern. await ?;
1371
1390
let mut results = Vec :: new ( ) ;
0 commit comments