Skip to content

Commit 33798df

Browse files
committed
Iterate over registered impls in reverse order
Going through the registered implementations in the opposite order that they were defined means that implementations that are defined later in a file are used instead of the ones earlier in the file when they overlap.
1 parent cdb2685 commit 33798df

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mypyc/irbuild/function.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,9 @@ def add_singledispatch_registered_impls(builder: IRBuilder) -> None:
779779
line = fitem.line
780780
current_func_decl = builder.mapper.func_to_decl[fitem]
781781
arg_info = get_args(builder, current_func_decl.sig.args, line)
782-
for dispatch_type, impl in impls:
782+
# Reverse the list of registered implementations so we use the implementations defined later
783+
# if there are multiple overlapping implementations
784+
for dispatch_type, impl in reversed(impls):
783785
func_decl = builder.mapper.func_to_decl[impl]
784786
call_impl, next_impl = BasicBlock(), BasicBlock()
785787
should_call_impl = check_if_isinstance(builder, arg_info.args[0], dispatch_type, line)

0 commit comments

Comments
 (0)