@@ -199,7 +199,7 @@ impl SwitchRuleOperator {
199199 ( Variant :: Object ( a) , Some ( b) ) => Ok ( a. contains_key ( b) ) ,
200200 _ => Ok ( false ) ,
201201 } ,
202- Self :: Else => Ok ( * a == Variant :: Bool ( true ) ) ,
202+ Self :: Else => Ok ( false ) ,
203203 _ => Err ( EdgelinkError :: NotSupported ( "Unsupported operator" . to_owned ( ) ) . into ( ) ) ,
204204 }
205205 }
@@ -406,32 +406,41 @@ impl SwitchNode {
406406 let msg = orig_msg. read ( ) . await ;
407407 let from_value = self . eval_property_value ( & msg) . await ?;
408408 let last_property_value = from_value. clone ( ) ;
409+ let mut matched = false ;
409410 for ( port, rule) in self . config . rules . iter ( ) . enumerate ( ) {
410- if rule. value_type == SwitchPropertyType :: Prev {
411- let prev_guard = self . prev_value . read ( ) . await ;
412- if prev_guard . is_null ( ) {
411+ if rule. operator == SwitchRuleOperator :: Else {
412+ // only match if no previous rule matched
413+ if !matched {
413414 envelopes. push ( Envelope { port, msg : orig_msg. clone ( ) } ) ;
415+ }
416+ // else never match
417+ } else {
418+ if rule. value_type == SwitchPropertyType :: Prev {
419+ let prev_guard = self . prev_value . read ( ) . await ;
420+ if prev_guard. is_null ( ) {
421+ envelopes. push ( Envelope { port, msg : orig_msg. clone ( ) } ) ;
422+ if !self . config . check_all {
423+ break ;
424+ }
425+ continue ;
426+ }
427+ }
428+ if rule. value2_type == Some ( SwitchPropertyType :: Prev ) {
429+ let prev_guard = self . prev_value . read ( ) . await ;
430+ if prev_guard. is_null ( ) {
431+ continue ;
432+ }
433+ }
434+ let v1 = self . get_v1 ( rule, & msg) . await ?;
435+ let v2 = self . get_v2 ( rule, & msg) . await ?;
436+ if rule. operator . apply ( & from_value, & v1, & v2, rule. case , & [ ] ) ? {
437+ envelopes. push ( Envelope { port, msg : orig_msg. clone ( ) } ) ;
438+ matched = true ;
414439 if !self . config . check_all {
415440 break ;
416441 }
417- continue ;
418- }
419- }
420- if rule. value2_type == Some ( SwitchPropertyType :: Prev ) {
421- let prev_guard = self . prev_value . read ( ) . await ;
422- if prev_guard. is_null ( ) {
423- continue ;
424442 }
425443 }
426- let v1 = self . get_v1 ( rule, & msg) . await ?;
427- let v2 = self . get_v2 ( rule, & msg) . await ?;
428- if rule. operator . apply ( & from_value, & v1, & v2, rule. case , & [ ] ) ? {
429- envelopes. push ( Envelope { port, msg : orig_msg. clone ( ) } ) ;
430- }
431-
432- if !self . config . check_all {
433- break ;
434- }
435444 }
436445 // Update prev_value
437446 if !last_property_value. is_null ( ) {
0 commit comments