(self, stmts: list[Statement])
| 616 | return b |
| 617 | |
| 618 | def fix_function_overloads(self, stmts: list[Statement]) -> list[Statement]: |
| 619 | ret: list[Statement] = [] |
| 620 | current_overload: list[OverloadPart] = [] |
| 621 | current_overload_name: str | None = None |
| 622 | last_unconditional_func_def: str | None = None |
| 623 | last_if_stmt: IfStmt | None = None |
| 624 | last_if_overload: Decorator | FuncDef | OverloadedFuncDef | None = None |
| 625 | last_if_stmt_overload_name: str | None = None |
| 626 | last_if_unknown_truth_value: IfStmt | None = None |
| 627 | skipped_if_stmts: list[IfStmt] = [] |
| 628 | for stmt in stmts: |
| 629 | if_overload_name: str | None = None |
| 630 | if_block_with_overload: Block | None = None |
| 631 | if_unknown_truth_value: IfStmt | None = None |
| 632 | if isinstance(stmt, IfStmt): |
| 633 | # Check IfStmt block to determine if function overloads can be merged |
| 634 | if_overload_name = self._check_ifstmt_for_overloads(stmt, current_overload_name) |
| 635 | if if_overload_name is not None: |
| 636 | if_block_with_overload, if_unknown_truth_value = ( |
| 637 | self._get_executable_if_block_with_overloads(stmt) |
| 638 | ) |
| 639 | |
| 640 | if ( |
| 641 | current_overload_name is not None |
| 642 | and isinstance(stmt, (Decorator, FuncDef)) |
| 643 | and stmt.name == current_overload_name |
| 644 | ): |
| 645 | if last_if_stmt is not None: |
| 646 | skipped_if_stmts.append(last_if_stmt) |
| 647 | if last_if_overload is not None: |
| 648 | # Last stmt was an IfStmt with same overload name |
| 649 | # Add overloads to current_overload |
| 650 | if isinstance(last_if_overload, OverloadedFuncDef): |
| 651 | current_overload.extend(last_if_overload.items) |
| 652 | else: |
| 653 | current_overload.append(last_if_overload) |
| 654 | last_if_stmt, last_if_overload = None, None |
| 655 | if last_if_unknown_truth_value: |
| 656 | self.fail_merge_overload(last_if_unknown_truth_value) |
| 657 | last_if_unknown_truth_value = None |
| 658 | current_overload.append(stmt) |
| 659 | if isinstance(stmt, FuncDef): |
| 660 | # This is, strictly speaking, wrong: there might be a decorated |
| 661 | # implementation. However, it only affects the error message we show: |
| 662 | # ideally it's "already defined", but "implementation must come last" |
| 663 | # is also reasonable. |
| 664 | # TODO: can we get rid of this completely and just always emit |
| 665 | # "implementation must come last" instead? |
| 666 | last_unconditional_func_def = stmt.name |
| 667 | elif ( |
| 668 | current_overload_name is not None |
| 669 | and isinstance(stmt, IfStmt) |
| 670 | and if_overload_name == current_overload_name |
| 671 | and last_unconditional_func_def != current_overload_name |
| 672 | ): |
| 673 | # IfStmt only contains stmts relevant to current_overload. |
| 674 | # Check if stmts are reachable and add them to current_overload, |
| 675 | # otherwise skip IfStmt to allow subsequent overload |
no test coverage detected