Commit 85989669 authored by Mark Florisson's avatar Mark Florisson

Fix ambiguous overload scoring error

parent b5b00d26
......@@ -3467,7 +3467,7 @@ def best_match(args, functions, pos=None, env=None):
elif ((src_type.is_int and dst_type.is_int) or
(src_type.is_float and dst_type.is_float)):
score[2] += abs(dst_type.rank + (not dst_type.signed) -
(src_type.rank + (not src_type.signed)))
(src_type.rank + (not src_type.signed))) + 1
elif not src_type.is_pyobject:
score[1] += 1
else:
......@@ -3482,10 +3482,13 @@ def best_match(args, functions, pos=None, env=None):
if possibilities:
possibilities.sort()
if len(possibilities) > 1 and possibilities[0][0] == possibilities[1][0]:
if pos is not None:
error(pos, "ambiguous overloaded method")
return None
if len(possibilities) > 1:
score1 = possibilities[0][0]
score2 = possibilities[1][0]
if score1 == score2:
if pos is not None:
error(pos, "ambiguous overloaded method")
return None
function = possibilities[0][-1]
......
......@@ -7,6 +7,9 @@ __doc__ = u"""
12.0
>>> test_square_area(15)
(225.0, 225.0)
>>> test_overload_bint_int()
202
201
"""
cdef extern from "shapes.h" namespace "shapes":
......@@ -23,6 +26,8 @@ cdef extern from "shapes.h" namespace "shapes":
int height
Rectangle()
Rectangle(int, int)
int method(int)
int method(bint)
cdef cppclass Square(Rectangle):
int side
......@@ -43,6 +48,17 @@ def test_rect_area(w, h):
finally:
del rect
def test_overload_bint_int():
cdef Rectangle *rect1 = new Rectangle(10, 20)
cdef Rectangle *rect2 = new Rectangle(10, 20)
try:
print rect1.method(<int> 2)
print rect2.method(<bint> True)
finally:
del rect1
del rect2
def test_square_area(w):
cdef Square *sqr = new Square(w)
cdef Rectangle *rect = sqr
......
......@@ -23,9 +23,15 @@ namespace shapes {
this->width = width;
this->height = height;
}
float area() { return width * height; }
int width;
int height;
int method(int arg) {
return width * height + arg;
}
};
class Square : public Rectangle
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment