ruchy 4.1.2

A systems scripting language that transpiles to idiomatic Rust with extreme quality engineering
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
//! Binary operator transpilation helpers

use super::super::Transpiler;
use crate::frontend::ast::{BinaryOp, Expr, ExprKind};
use anyhow::Result;
use proc_macro2::TokenStream;
use quote::quote;

impl Transpiler {
    pub fn transpile_binary(&self, left: &Expr, op: BinaryOp, right: &Expr) -> Result<TokenStream> {
        // Special handling for string concatenation
        // Only treat as string concatenation if at least one operand is definitely a string
        // DEFECT-016 FIX: Use instance method to access mutable_vars context
        if op == BinaryOp::Add
            && (self.is_definitely_string(left) || self.is_definitely_string(right))
        {
            return self.transpile_string_concatenation(left, right);
        }

        // TRANSPILER-005: Handle vector + array concatenation
        // Pattern: vec + [item] → [vec, vec![item]].concat()
        if op == BinaryOp::Add && Self::is_vec_array_concat(left, right) {
            return self.transpile_vec_concatenation(left, right);
        }

        // ISSUE-114 FIX: Handle usize casting for .len() comparisons
        // When comparing .len() (usize) with i32, cast i32 to usize
        if Self::is_comparison_op(op) {
            let left_is_len = Self::is_len_call(left);
            let right_is_len = Self::is_len_call(right);

            if left_is_len && !right_is_len {
                // left.len() < right → left.len() < (right as usize)
                let left_tokens = self.transpile_expr_with_precedence(left, op, true)?;
                let right_tokens = self.transpile_expr_with_precedence(right, op, false)?;
                let casted_right = quote! { (#right_tokens as usize) };
                return Ok(Self::transpile_binary_op(left_tokens, op, casted_right));
            } else if right_is_len && !left_is_len {
                // left > right.len() → (left as usize) > right.len()
                let left_tokens = self.transpile_expr_with_precedence(left, op, true)?;
                let right_tokens = self.transpile_expr_with_precedence(right, op, false)?;
                let casted_left = quote! { (#left_tokens as usize) };
                return Ok(Self::transpile_binary_op(casted_left, op, right_tokens));
            }
        }

        // BOOK-COMPAT-009: Handle mixed int/float arithmetic
        // When one operand is int and other is float, cast both to f64
        if Self::is_arithmetic_op(op) {
            let left_is_int = Self::is_integer_literal(left);
            let left_is_float = Self::is_float_literal(left);
            let right_is_int = Self::is_integer_literal(right);
            let right_is_float = Self::is_float_literal(right);

            if (left_is_int && right_is_float) || (left_is_float && right_is_int) {
                let left_tokens = self.transpile_expr(left)?;
                let right_tokens = self.transpile_expr(right)?;
                // Cast both to f64 for mixed arithmetic
                let casted_left = quote! { (#left_tokens as f64) };
                let casted_right = quote! { (#right_tokens as f64) };
                return Ok(Self::transpile_binary_op(casted_left, op, casted_right));
            }
        }

        // Transpile operands with precedence-aware parentheses
        let left_tokens = self.transpile_expr_with_precedence(left, op, true)?;
        let right_tokens = self.transpile_expr_with_precedence(right, op, false)?;
        Ok(Self::transpile_binary_op(left_tokens, op, right_tokens))
    }
    /// Transpile expression with precedence-aware parentheses
    ///
    /// Adds parentheses around sub-expressions when needed to preserve precedence
    fn transpile_expr_with_precedence(
        &self,
        expr: &Expr,
        parent_op: BinaryOp,
        is_left_operand: bool,
    ) -> Result<TokenStream> {
        let tokens = self.transpile_expr(expr)?;
        // Check if we need parentheses
        if let ExprKind::Binary { op: child_op, .. } = &expr.kind {
            let parent_prec = Self::get_operator_precedence(parent_op);
            let child_prec = Self::get_operator_precedence(*child_op);
            // Add parentheses if child has lower precedence
            // For right operands, also add parentheses if precedence is equal and parent is right-associative
            let needs_parens = child_prec < parent_prec
                || (!is_left_operand
                    && child_prec == parent_prec
                    && Self::is_right_associative(parent_op));
            if needs_parens {
                return Ok(quote! { (#tokens) });
            }
        }
        Ok(tokens)
    }
    /// Get operator precedence (higher number = higher precedence)
    fn get_operator_precedence(op: BinaryOp) -> i32 {
        match op {
            BinaryOp::Or => 10,
            BinaryOp::And => 20,
            BinaryOp::Equal | BinaryOp::NotEqual => 30,
            BinaryOp::Less
            | BinaryOp::LessEqual
            | BinaryOp::Greater
            | BinaryOp::GreaterEqual
            | BinaryOp::In => 40,
            BinaryOp::Add | BinaryOp::Subtract => 50,
            BinaryOp::Multiply | BinaryOp::Divide | BinaryOp::Modulo => 60,
            BinaryOp::Power => 70,
            BinaryOp::Send => 15, // Actor message passing
            _ => 0,               // Default for other operators
        }
    }
    /// Check if operator is right-associative
    fn is_right_associative(op: BinaryOp) -> bool {
        matches!(op, BinaryOp::Power) // Only power is right-associative in most languages
    }
    fn transpile_binary_op(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        use BinaryOp::{
            Add, And, BitwiseAnd, BitwiseOr, BitwiseXor, Divide, Equal, Greater, GreaterEqual, In,
            LeftShift, Less, LessEqual, Modulo, Multiply, NotEqual, NullCoalesce, Or, Power,
            RightShift, Send, Subtract,
        };
        match op {
            // Arithmetic operations
            Add | Subtract | Multiply | Divide | Modulo | Power => {
                Self::transpile_arithmetic_op(left, op, right)
            }
            // Comparison operations
            Equal | NotEqual | Less | LessEqual | Greater | GreaterEqual | BinaryOp::Gt => {
                Self::transpile_comparison_op(left, op, right)
            }
            // Containment operations (Python-style 'in' operator)
            In => quote! { #right.contains(&#left) },
            // Logical operations
            And | Or | NullCoalesce => Self::transpile_logical_op(left, op, right),
            // Bitwise operations
            BitwiseAnd | BitwiseOr | BitwiseXor => Self::transpile_bitwise_op(left, op, right),
            // Shift operations
            LeftShift => Self::transpile_shift_ops(left, op, right),
            RightShift => Self::transpile_shift_ops(left, op, right),
            // Actor operations
            Send => quote! { #left.send(#right) },
        }
    }
    fn transpile_arithmetic_op(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        use BinaryOp::{Add, Divide, Modulo, Multiply, Power, Subtract};
        match op {
            Add | Subtract | Multiply | Divide | Modulo => {
                Self::transpile_basic_arithmetic(left, op, right)
            }
            // BOOK-COMPAT-013: Use powf for float exponents (f64.pow takes i32)
            Power => quote! { #left.powf(#right) },
            _ => unreachable!(),
        }
    }
    fn transpile_basic_arithmetic(
        left: TokenStream,
        op: BinaryOp,
        right: TokenStream,
    ) -> TokenStream {
        // Reduce complexity by splitting into smaller functions
        match op {
            BinaryOp::Add => quote! { #left + #right },
            BinaryOp::Subtract => quote! { #left - #right },
            BinaryOp::Multiply => quote! { #left * #right },
            _ => Self::transpile_division_mod(left, op, right),
        }
    }
    fn transpile_division_mod(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        match op {
            BinaryOp::Divide => quote! { #left / #right },
            BinaryOp::Modulo => quote! { #left % #right },
            _ => unreachable!(),
        }
    }
    fn transpile_comparison_op(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        use BinaryOp::{Equal, Greater, GreaterEqual, Less, LessEqual, NotEqual};
        match op {
            Equal | NotEqual => Self::transpile_equality(left, op, right),
            Less | LessEqual | Greater | GreaterEqual | BinaryOp::Gt => {
                Self::transpile_ordering(left, op, right)
            }
            _ => unreachable!(),
        }
    }
    fn transpile_equality(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        match op {
            BinaryOp::Equal => quote! { #left == #right },
            BinaryOp::NotEqual => quote! { #left != #right },
            _ => unreachable!(),
        }
    }
    fn transpile_ordering(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        match op {
            BinaryOp::Less => quote! { #left < #right },
            BinaryOp::LessEqual => quote! { #left <= #right },
            _ => Self::transpile_greater_ops(left, op, right),
        }
    }
    fn transpile_greater_ops(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        match op {
            BinaryOp::Greater => quote! { #left > #right },
            BinaryOp::GreaterEqual => quote! { #left >= #right },
            BinaryOp::Gt => quote! { #left > #right }, // Alias for Greater
            _ => unreachable!(),
        }
    }
    fn transpile_logical_op(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        match op {
            BinaryOp::And => quote! { #left && #right },
            BinaryOp::Or => quote! { #left || #right },
            BinaryOp::NullCoalesce => quote! { #left.unwrap_or(#right) },
            _ => unreachable!(),
        }
    }
    fn transpile_bitwise_op(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        use BinaryOp::{BitwiseAnd, BitwiseOr, BitwiseXor};
        match op {
            BitwiseAnd => quote! { #left & #right },
            BitwiseOr => quote! { #left | #right },
            BitwiseXor => quote! { #left ^ #right },
            _ => Self::transpile_shift_ops(left, op, right),
        }
    }
    fn transpile_shift_ops(left: TokenStream, op: BinaryOp, right: TokenStream) -> TokenStream {
        match op {
            BinaryOp::LeftShift => quote! { #left << #right },
            BinaryOp::RightShift => quote! { #left >> #right },
            _ => unreachable!("Invalid shift operation: {:?}", op),
        }
    }

    /// Check if an expression is a .`len()` method call OR `len()` function call (ISSUE-115)
    /// Returns true for: `vec.len()`, `string.len()`, len(vec), len(string), etc.
    /// TRANSPILER-004: Extended to detect `len()` function calls for usize casting
    fn is_len_call(expr: &Expr) -> bool {
        match &expr.kind {
            // Method call: vec.len()
            ExprKind::MethodCall { method, .. } if method == "len" => true,
            // Function call: len(vec) - TRANSPILER-004 fix
            ExprKind::Call { func, args } if args.len() == 1 => {
                matches!(&func.kind, ExprKind::Identifier(name) if name == "len")
            }
            _ => false,
        }
    }

    /// Check if operator is a comparison operator (ISSUE-114)
    fn is_comparison_op(op: BinaryOp) -> bool {
        matches!(
            op,
            BinaryOp::Less
                | BinaryOp::LessEqual
                | BinaryOp::Greater
                | BinaryOp::GreaterEqual
                | BinaryOp::Equal
                | BinaryOp::NotEqual
        )
    }

    /// Check if operator is an arithmetic operator (BOOK-COMPAT-009)
    fn is_arithmetic_op(op: BinaryOp) -> bool {
        matches!(
            op,
            BinaryOp::Add
                | BinaryOp::Subtract
                | BinaryOp::Multiply
                | BinaryOp::Divide
                | BinaryOp::Modulo
                | BinaryOp::Power
        )
    }

    /// Check if expression is an integer literal (BOOK-COMPAT-009)
    fn is_integer_literal(expr: &Expr) -> bool {
        use crate::frontend::ast::Literal;
        matches!(&expr.kind, ExprKind::Literal(Literal::Integer(_, _)))
    }

    /// Check if expression is a float literal (BOOK-COMPAT-009)
    fn is_float_literal(expr: &Expr) -> bool {
        use crate::frontend::ast::Literal;
        matches!(&expr.kind, ExprKind::Literal(Literal::Float(_)))
    }

    /// Check if this is a vector + array concatenation pattern (TRANSPILER-005)
    /// Returns true for: vec + [item], vec + [item1, item2], etc.
    /// Complexity: 2 (within ≤10 limit ✅)
    fn is_vec_array_concat(_left: &Expr, right: &Expr) -> bool {
        // Right side must be an array literal
        let right_is_array = matches!(&right.kind, ExprKind::List(_));

        // Left side should be a vec-like expression (identifier, method call, etc.)
        // We use a conservative check: if right is array, assume left might be vec
        right_is_array
    }

    /// Transpile vector concatenation to valid Rust (TRANSPILER-005)
    /// Pattern: vec + [item] → [`vec.as_slice()`, &[item]].`concat()`
    /// Complexity: 3 (within ≤10 limit ✅)
    fn transpile_vec_concatenation(&self, left: &Expr, right: &Expr) -> Result<TokenStream> {
        let left_tokens = self.transpile_expr(left)?;
        let right_tokens = self.transpile_expr(right)?;

        // Generate: [left.as_slice(), &right].concat()
        // This works for Vec + array and handles ownership correctly
        Ok(quote! { [#left_tokens.as_slice(), &#right_tokens].concat() })
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use quote::quote;

    // Test 1: get_operator_precedence - Or (lowest)
    #[test]
    fn test_get_operator_precedence_or() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Or), 10);
    }

    // Test 2: get_operator_precedence - And
    #[test]
    fn test_get_operator_precedence_and() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::And), 20);
    }

    // Test 3: get_operator_precedence - comparison operators
    #[test]
    fn test_get_operator_precedence_comparison() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Equal), 30);
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Less), 40);
    }

    // Test 4: get_operator_precedence - arithmetic Add/Subtract
    #[test]
    fn test_get_operator_precedence_add_subtract() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Add), 50);
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Subtract), 50);
    }

    // Test 5: get_operator_precedence - arithmetic Multiply/Divide
    #[test]
    fn test_get_operator_precedence_multiply_divide() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Multiply), 60);
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Divide), 60);
    }

    // Test 6: get_operator_precedence - Power (highest)
    #[test]
    fn test_get_operator_precedence_power() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Power), 70);
    }

    // Test 7: is_right_associative - Power is right-associative
    #[test]
    fn test_is_right_associative_power() {
        assert!(Transpiler::is_right_associative(BinaryOp::Power));
    }

    // Test 8: is_right_associative - Add is left-associative
    #[test]
    fn test_is_right_associative_add() {
        assert!(!Transpiler::is_right_associative(BinaryOp::Add));
    }

    // Test 9: transpile_binary_op - Add arithmetic
    #[test]
    fn test_transpile_binary_op_add() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Add, right);
        assert_eq!(result.to_string(), "a + b");
    }

    // Test 10: transpile_binary_op - Subtract arithmetic
    #[test]
    fn test_transpile_binary_op_subtract() {
        let left = quote! { x };
        let right = quote! { y };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Subtract, right);
        assert_eq!(result.to_string(), "x - y");
    }

    // Test 11: transpile_binary_op - Multiply arithmetic
    #[test]
    fn test_transpile_binary_op_multiply() {
        let left = quote! { m };
        let right = quote! { n };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Multiply, right);
        assert_eq!(result.to_string(), "m * n");
    }

    // Test 12: transpile_binary_op - Divide arithmetic
    #[test]
    fn test_transpile_binary_op_divide() {
        let left = quote! { p };
        let right = quote! { q };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Divide, right);
        assert_eq!(result.to_string(), "p / q");
    }

    // Test 13: transpile_binary_op - Modulo arithmetic
    #[test]
    fn test_transpile_binary_op_modulo() {
        let left = quote! { r };
        let right = quote! { s };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Modulo, right);
        assert_eq!(result.to_string(), "r % s");
    }

    // Test 14: transpile_binary_op - Power arithmetic
    #[test]
    fn test_transpile_binary_op_power() {
        // BOOK-COMPAT-013: Use powf for float exponents (f64.pow takes i32)
        let left = quote! { base };
        let right = quote! { exp };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Power, right);
        assert_eq!(result.to_string(), "base . powf (exp)");
    }

    // Test 15: transpile_binary_op - Equal comparison
    #[test]
    fn test_transpile_binary_op_equal() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Equal, right);
        assert_eq!(result.to_string(), "a == b");
    }

    // Test 16: transpile_binary_op - NotEqual comparison
    #[test]
    fn test_transpile_binary_op_not_equal() {
        let left = quote! { x };
        let right = quote! { y };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::NotEqual, right);
        assert_eq!(result.to_string(), "x != y");
    }

    // Test 17: transpile_binary_op - Less comparison
    #[test]
    fn test_transpile_binary_op_less() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Less, right);
        assert_eq!(result.to_string(), "a < b");
    }

    // Test 18: transpile_binary_op - Greater comparison
    #[test]
    fn test_transpile_binary_op_greater() {
        let left = quote! { x };
        let right = quote! { y };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Greater, right);
        assert_eq!(result.to_string(), "x > y");
    }

    // Test 19: transpile_binary_op - And logical
    #[test]
    fn test_transpile_binary_op_and() {
        let left = quote! { cond1 };
        let right = quote! { cond2 };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::And, right);
        assert_eq!(result.to_string(), "cond1 && cond2");
    }

    // Test 20: transpile_binary_op - Or logical
    #[test]
    fn test_transpile_binary_op_or() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Or, right);
        assert_eq!(result.to_string(), "a || b");
    }

    // Test 21: transpile_binary_op - BitwiseAnd
    #[test]
    fn test_transpile_binary_op_bitwise_and() {
        let left = quote! { flags1 };
        let right = quote! { flags2 };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::BitwiseAnd, right);
        assert_eq!(result.to_string(), "flags1 & flags2");
    }

    // Test 22: transpile_binary_op - BitwiseOr
    #[test]
    fn test_transpile_binary_op_bitwise_or() {
        let left = quote! { mask1 };
        let right = quote! { mask2 };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::BitwiseOr, right);
        assert_eq!(result.to_string(), "mask1 | mask2");
    }

    // Test 23: transpile_binary_op - LeftShift
    #[test]
    fn test_transpile_binary_op_left_shift() {
        let left = quote! { value };
        let right = quote! { bits };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::LeftShift, right);
        assert_eq!(result.to_string(), "value << bits");
    }

    // Test 24: transpile_binary_op - RightShift
    #[test]
    fn test_transpile_binary_op_right_shift() {
        let left = quote! { num };
        let right = quote! { shift };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::RightShift, right);
        assert_eq!(result.to_string(), "num >> shift");
    }

    // Test 25: is_comparison_op - Equal is comparison
    #[test]
    fn test_is_comparison_op_equal() {
        assert!(Transpiler::is_comparison_op(BinaryOp::Equal));
    }

    // Test 26: is_comparison_op - Less is comparison
    #[test]
    fn test_is_comparison_op_less() {
        assert!(Transpiler::is_comparison_op(BinaryOp::Less));
    }

    // Test 27: is_comparison_op - Add is NOT comparison
    #[test]
    fn test_is_comparison_op_add() {
        assert!(!Transpiler::is_comparison_op(BinaryOp::Add));
    }

    // Test 28: transpile_binary_op - NullCoalesce
    #[test]
    fn test_transpile_binary_op_null_coalesce() {
        let left = quote! { opt };
        let right = quote! { default };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::NullCoalesce, right);
        assert_eq!(result.to_string(), "opt . unwrap_or (default)");
    }

    // Test 29: transpile_binary_op - Send (actor operation)
    #[test]
    fn test_transpile_binary_op_send() {
        let left = quote! { actor };
        let right = quote! { message };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Send, right);
        assert_eq!(result.to_string(), "actor . send (message)");
    }

    // Test 30: transpile_binary_op - GreaterEqual comparison
    #[test]
    fn test_transpile_binary_op_greater_equal() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::GreaterEqual, right);
        assert_eq!(result.to_string(), "a >= b");
    }

    // ===== EXTREME TDD Round 142 - Additional Coverage Tests =====

    // Test 31: is_len_call with method call
    #[test]
    fn test_is_len_call_method() {
        use crate::frontend::ast::{Expr, ExprKind, Span};
        let receiver = Expr {
            kind: ExprKind::Identifier("vec".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        let expr = Expr {
            kind: ExprKind::MethodCall {
                receiver: Box::new(receiver),
                method: "len".to_string(),
                args: vec![],
            },
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        assert!(Transpiler::is_len_call(&expr));
    }

    // Test 32: is_len_call with function call
    #[test]
    fn test_is_len_call_function() {
        use crate::frontend::ast::{Expr, ExprKind, Span};
        let func = Expr {
            kind: ExprKind::Identifier("len".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        let arg = Expr {
            kind: ExprKind::Identifier("vec".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        let expr = Expr {
            kind: ExprKind::Call {
                func: Box::new(func),
                args: vec![arg],
            },
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        assert!(Transpiler::is_len_call(&expr));
    }

    // Test 33: is_len_call with non-len method
    #[test]
    fn test_is_len_call_not_len() {
        use crate::frontend::ast::{Expr, ExprKind, Span};
        let receiver = Expr {
            kind: ExprKind::Identifier("vec".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        let expr = Expr {
            kind: ExprKind::MethodCall {
                receiver: Box::new(receiver),
                method: "push".to_string(),
                args: vec![],
            },
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        assert!(!Transpiler::is_len_call(&expr));
    }

    // Test 34: is_comparison_op - GreaterEqual
    #[test]
    fn test_is_comparison_op_greater_equal() {
        assert!(Transpiler::is_comparison_op(BinaryOp::GreaterEqual));
    }

    // Test 35: is_comparison_op - LessEqual
    #[test]
    fn test_is_comparison_op_less_equal() {
        assert!(Transpiler::is_comparison_op(BinaryOp::LessEqual));
    }

    // Test 36: is_comparison_op - NotEqual
    #[test]
    fn test_is_comparison_op_not_equal() {
        assert!(Transpiler::is_comparison_op(BinaryOp::NotEqual));
    }

    // Test 37: is_comparison_op - Greater
    #[test]
    fn test_is_comparison_op_greater() {
        assert!(Transpiler::is_comparison_op(BinaryOp::Greater));
    }

    // Test 38: is_comparison_op - Multiply NOT comparison
    #[test]
    fn test_is_comparison_op_multiply() {
        assert!(!Transpiler::is_comparison_op(BinaryOp::Multiply));
    }

    // Test 39: is_vec_array_concat with list right
    #[test]
    fn test_is_vec_array_concat_with_list() {
        use crate::frontend::ast::{Expr, ExprKind, Literal, Span};
        let left = Expr {
            kind: ExprKind::Identifier("vec".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        let right = Expr {
            kind: ExprKind::List(vec![Expr {
                kind: ExprKind::Literal(Literal::Integer(1, None)),
                span: Span::default(),
                attributes: vec![],
                leading_comments: vec![],
                trailing_comment: None,
            }]),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        assert!(Transpiler::is_vec_array_concat(&left, &right));
    }

    // Test 40: is_vec_array_concat with non-list right
    #[test]
    fn test_is_vec_array_concat_not_list() {
        use crate::frontend::ast::{Expr, ExprKind, Span};
        let left = Expr {
            kind: ExprKind::Identifier("vec".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        let right = Expr {
            kind: ExprKind::Identifier("other".to_string()),
            span: Span::default(),
            attributes: vec![],
            leading_comments: vec![],
            trailing_comment: None,
        };
        assert!(!Transpiler::is_vec_array_concat(&left, &right));
    }

    // Test 41: get_operator_precedence - Modulo
    #[test]
    fn test_get_operator_precedence_modulo() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Modulo), 60);
    }

    // Test 42: get_operator_precedence - Send
    #[test]
    fn test_get_operator_precedence_send() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::Send), 15);
    }

    // Test 43: get_operator_precedence - In
    #[test]
    fn test_get_operator_precedence_in() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::In), 40);
    }

    // Test 44: get_operator_precedence - NotEqual
    #[test]
    fn test_get_operator_precedence_not_equal() {
        assert_eq!(Transpiler::get_operator_precedence(BinaryOp::NotEqual), 30);
    }

    // Test 45: transpile_binary_op - In operator
    #[test]
    fn test_transpile_binary_op_in() {
        let left = quote! { item };
        let right = quote! { collection };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::In, right);
        assert_eq!(result.to_string(), "collection . contains (& item)");
    }

    // Test 46: transpile_binary_op - BitwiseXor
    #[test]
    fn test_transpile_binary_op_bitwise_xor() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::BitwiseXor, right);
        assert_eq!(result.to_string(), "a ^ b");
    }

    // Test 47: transpile_binary_op - LessEqual
    #[test]
    fn test_transpile_binary_op_less_equal() {
        let left = quote! { x };
        let right = quote! { y };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::LessEqual, right);
        assert_eq!(result.to_string(), "x <= y");
    }

    // Test 48: is_right_associative - Multiply is NOT right-associative
    #[test]
    fn test_is_right_associative_multiply() {
        assert!(!Transpiler::is_right_associative(BinaryOp::Multiply));
    }

    // Test 49: is_right_associative - Or is NOT right-associative
    #[test]
    fn test_is_right_associative_or() {
        assert!(!Transpiler::is_right_associative(BinaryOp::Or));
    }

    // Test 50: transpile_binary_op - Gt alias
    #[test]
    fn test_transpile_binary_op_gt() {
        let left = quote! { a };
        let right = quote! { b };
        let result = Transpiler::transpile_binary_op(left, BinaryOp::Gt, right);
        assert_eq!(result.to_string(), "a > b");
    }
}