mt-lang 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -627,7 +627,7 @@ module MilkTea
627
627
  raise_sema_error("match on #{scrutinee_type} is missing cases: #{missing_members.join(', ')}")
628
628
  end
629
629
 
630
- def check_integer_match_stmt(statement, scrutinee_type, scopes:, return_type:, allow_return:)
630
+ def each_integer_match_arm(statement, scrutinee_type, scopes:)
631
631
  has_wildcard = statement.arms.any? { |arm| wildcard_pattern?(arm.pattern) }
632
632
  raise_sema_error("match on integer type #{scrutinee_type} requires a wildcard arm (_:)") unless has_wildcard
633
633
 
@@ -635,16 +635,17 @@ module MilkTea
635
635
  wildcard_seen = false
636
636
  statement.arms.each do |arm|
637
637
  if arm.pattern.is_a?(AST::ErrorExpr)
638
- check_recovered_match_arm_body(arm, scopes:, return_type:, allow_return:)
638
+ yield arm
639
639
  next
640
640
  end
641
641
 
642
642
  if wildcard_pattern?(arm.pattern)
643
643
  raise_sema_error("duplicate wildcard arm in match") if wildcard_seen
644
644
  wildcard_seen = true
645
- check_block(arm.body, scopes:, return_type:, allow_return:)
645
+ yield arm
646
646
  next
647
647
  end
648
+
648
649
  if arm.pattern.is_a?(AST::RangeExpr)
649
650
  start_val = arm.pattern.start_expr
650
651
  end_val = arm.pattern.end_expr
@@ -659,20 +660,23 @@ module MilkTea
659
660
  raise_sema_error("duplicate match arm range #{range_key[0]}..#{range_key[1]}") if covered_values.key?(range_key)
660
661
 
661
662
  covered_values[range_key] = true
662
- check_block(arm.body, scopes:, return_type:, allow_return:)
663
+ yield arm
663
664
  next
664
665
  end
666
+
665
667
  unless arm.pattern.is_a?(AST::IntegerLiteral) || arm.pattern.is_a?(AST::CharLiteral)
666
668
  raise_sema_error("match arm for integer scrutinee must be an integer literal, char literal, range, or _, got #{arm.pattern.class.name}")
667
669
  end
670
+
668
671
  value = arm.pattern.value
669
672
  raise_sema_error("duplicate match arm value #{value}") if covered_values.key?(value)
673
+
670
674
  covered_values[value] = true
671
- check_block(arm.body, scopes:, return_type:, allow_return:)
675
+ yield arm
672
676
  end
673
677
  end
674
678
 
675
- def check_string_match_stmt(statement, scrutinee_type, scopes:, return_type:, allow_return:)
679
+ def each_string_match_arm(statement, scrutinee_type, scopes:)
676
680
  has_wildcard = statement.arms.any? { |arm| wildcard_pattern?(arm.pattern) }
677
681
  raise_sema_error("match on str requires a wildcard arm (_:)") unless has_wildcard
678
682
 
@@ -680,27 +684,30 @@ module MilkTea
680
684
  wildcard_seen = false
681
685
  statement.arms.each do |arm|
682
686
  if arm.pattern.is_a?(AST::ErrorExpr)
683
- check_recovered_match_arm_body(arm, scopes:, return_type:, allow_return:)
687
+ yield arm
684
688
  next
685
689
  end
686
690
 
687
691
  if wildcard_pattern?(arm.pattern)
688
692
  raise_sema_error("duplicate wildcard arm in match") if wildcard_seen
689
693
  wildcard_seen = true
690
- check_block(arm.body, scopes:, return_type:, allow_return:)
694
+ yield arm
691
695
  next
692
696
  end
697
+
693
698
  unless arm.pattern.is_a?(AST::StringLiteral)
694
699
  raise_sema_error("match arm for str scrutinee must be a string literal or _, got #{arm.pattern.class.name}")
695
700
  end
701
+
696
702
  value = arm.pattern.value
697
703
  raise_sema_error("duplicate match arm value \"#{value}\"") if covered_values.key?(value)
704
+
698
705
  covered_values[value] = true
699
- check_block(arm.body, scopes:, return_type:, allow_return:)
706
+ yield arm
700
707
  end
701
708
  end
702
709
 
703
- def check_tuple_match_stmt(statement, scrutinee_type, scopes:, return_type:, allow_return:)
710
+ def each_tuple_match_arm(statement, scrutinee_type, scopes:)
704
711
  has_wildcard = statement.arms.any? { |arm| wildcard_pattern?(arm.pattern) }
705
712
  raise_sema_error("match on tuple type #{scrutinee_type} requires a wildcard arm (_:)") unless has_wildcard
706
713
 
@@ -710,14 +717,14 @@ module MilkTea
710
717
 
711
718
  statement.arms.each do |arm|
712
719
  if arm.pattern.is_a?(AST::ErrorExpr)
713
- check_recovered_match_arm_body(arm, scopes:, return_type:, allow_return:)
720
+ yield arm
714
721
  next
715
722
  end
716
723
 
717
724
  if wildcard_pattern?(arm.pattern)
718
725
  raise_sema_error("duplicate wildcard arm in match") if wildcard_seen
719
726
  wildcard_seen = true
720
- check_block(arm.body, scopes:, return_type:, allow_return:)
727
+ yield arm
721
728
  next
722
729
  end
723
730
 
@@ -745,6 +752,24 @@ module MilkTea
745
752
  covered_values[values] = true
746
753
  end
747
754
 
755
+ yield arm
756
+ end
757
+ end
758
+
759
+ def check_integer_match_stmt(statement, scrutinee_type, scopes:, return_type:, allow_return:)
760
+ each_integer_match_arm(statement, scrutinee_type, scopes:) do |arm|
761
+ check_block(arm.body, scopes:, return_type:, allow_return:)
762
+ end
763
+ end
764
+
765
+ def check_string_match_stmt(statement, scrutinee_type, scopes:, return_type:, allow_return:)
766
+ each_string_match_arm(statement, scrutinee_type, scopes:) do |arm|
767
+ check_block(arm.body, scopes:, return_type:, allow_return:)
768
+ end
769
+ end
770
+
771
+ def check_tuple_match_stmt(statement, scrutinee_type, scopes:, return_type:, allow_return:)
772
+ each_tuple_match_arm(statement, scrutinee_type, scopes:) do |arm|
748
773
  check_block(arm.body, scopes:, return_type:, allow_return:)
749
774
  end
750
775
  end