Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/cpyrt/CPPMethod.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ int cpyrt::CPPMethod::GetPriority() {
if (scope)
priority += static_cast<int>(interop::GetNumBasesLongestBranch(scope));

if (interop::IsEnumScope(scope))
// GetScope does not resolve enum names, so also detect enums by type
if (interop::IsEnumScope(scope) ||
interop::IsEnumType(interop::GetMethodArgType(fMethod, iarg)))
priority -= 100;

// a couple of special cases as explained above
Expand Down
21 changes: 21 additions & 0 deletions test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,3 +1643,24 @@ def test52_no_cpp_name_for_template_arg(self):

with raises(TypeError):
cppjit.gbl.std.vector[object()]

def test53_enum_arg_overload_priority(self):
"""An integer argument prefers the integer overload over an enum one"""

import cppjit

cppjit.cppdef("""\
namespace EnumArgPriority {
enum Color { Red = 0, Green = 1, Blue = 2 };
int pick(Color) { return 1; }
int pick(unsigned int) { return 2; }
int only_enum(Color c) { return 10 + (int)c; }
}""")

ns = cppjit.gbl.EnumArgPriority

# C++ has no implicit int -> enum conversion
assert ns.pick(2) == 2

# an enum parameter is only deprioritized, never unusable
assert ns.only_enum(2) == 12
Loading