Skip to content

Commit

Permalink
Iterate over registered impls in reverse order
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pranavrajpal committed Jul 8, 2021
1 parent cdb2685 commit 33798df
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mypyc/irbuild/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,9 @@ def add_singledispatch_registered_impls(builder: IRBuilder) -> None:
line = fitem.line
current_func_decl = builder.mapper.func_to_decl[fitem]
arg_info = get_args(builder, current_func_decl.sig.args, line)
for dispatch_type, impl in impls:
# Reverse the list of registered implementations so we use the implementations defined later
# if there are multiple overlapping implementations
for dispatch_type, impl in reversed(impls):
func_decl = builder.mapper.func_to_decl[impl]
call_impl, next_impl = BasicBlock(), BasicBlock()
should_call_impl = check_if_isinstance(builder, arg_info.args[0], dispatch_type, line)
Expand Down

0 comments on commit 33798df

Please sign in to comment.