@@ -874,6 +874,8 @@ impl CELParser {
874874 /// Returns an error if the condition is missing, if a `{` or `}` delimiter is missing,
875875 /// if the then-branch or else-branch expression is missing, or if the then and else
876876 /// branch types do not match (as detected by `join2`).
877+ ///
878+ /// - Postcondition: Returns `Ok(true)` on success; `Ok(false)` is never returned.
877879 fn is_if_expression ( & mut self ) -> Result < bool > {
878880 if !self . is_or_expression ( ) ? {
879881 return Err ( self . error_at ( "expected condition after `if`" ) ) ;
@@ -1648,6 +1650,13 @@ mod tests {
16481650 assert ! ( parser. parse_str( "1i32 && true" ) . is_err( ) ) ;
16491651 }
16501652
1653+ #[ test]
1654+ fn or_lhs_type_error ( ) {
1655+ // LHS is i32, not bool — join2 must reject it at parse time.
1656+ let mut parser = CELParser :: new ( OpLookup :: new ( ) ) ;
1657+ assert ! ( parser. parse_str( "1i32 || true" ) . is_err( ) ) ;
1658+ }
1659+
16511660 #[ test]
16521661 fn or_short_circuits_on_true ( ) {
16531662 // Without short-circuit the RHS executes and division-by-zero errors.
@@ -1759,6 +1768,13 @@ mod tests {
17591768 . expect ( "should parse" ) ;
17601769 segment. call0 :: < ( ) > ( ) . expect ( "should execute" ) ;
17611770 }
1771+
1772+ #[ test]
1773+ fn if_trailing_else_is_error ( ) {
1774+ // `else` with no body is a parse error.
1775+ let mut parser = CELParser :: new ( OpLookup :: new ( ) ) ;
1776+ assert ! ( parser. parse_str( "if true { () } else" ) . is_err( ) ) ;
1777+ }
17621778}
17631779
17641780#[ cfg( test) ]
0 commit comments