diff --git a/pymbolic/mapper/optimize.py b/pymbolic/mapper/optimize.py index 5be7d6841c03c660353ce73c366919e4e144b7b0..b492e224b93af81c3fce3a6dcef19d4abfcc66a5 100644 --- a/pymbolic/mapper/optimize.py +++ b/pymbolic/mapper/optimize.py @@ -53,7 +53,9 @@ def _get_def_from_ast_container( name: str, node_type: type[AstDefNodeT] ) -> AstDefNodeT: - for entry in container: + # Return the last definition in the container, not the first. + # This is relevant, e.g., in the case of @overload of methods. + for entry in reversed(list(container)): if isinstance(entry, node_type) and entry.name == name: return entry