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): ...@@ -3467,7 +3467,7 @@ def best_match(args, functions, pos=None, env=None):
elif ((src_type.is_int and dst_type.is_int) or elif ((src_type.is_int and dst_type.is_int) or
(src_type.is_float and dst_type.is_float)): (src_type.is_float and dst_type.is_float)):
score[2] += abs(dst_type.rank + (not dst_type.signed) - 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: elif not src_type.is_pyobject:
score[1] += 1 score[1] += 1
else: else:
...@@ -3482,10 +3482,13 @@ def best_match(args, functions, pos=None, env=None): ...@@ -3482,10 +3482,13 @@ def best_match(args, functions, pos=None, env=None):
if possibilities: if possibilities:
possibilities.sort() possibilities.sort()
if len(possibilities) > 1 and possibilities[0][0] == possibilities[1][0]: if len(possibilities) > 1:
if pos is not None: score1 = possibilities[0][0]
error(pos, "ambiguous overloaded method") score2 = possibilities[1][0]
return None if score1 == score2:
if pos is not None:
error(pos, "ambiguous overloaded method")
return None
function = possibilities[0][-1] function = possibilities[0][-1]
......
...@@ -7,6 +7,9 @@ __doc__ = u""" ...@@ -7,6 +7,9 @@ __doc__ = u"""
12.0 12.0
>>> test_square_area(15) >>> test_square_area(15)
(225.0, 225.0) (225.0, 225.0)
>>> test_overload_bint_int()
202
201
""" """
cdef extern from "shapes.h" namespace "shapes": cdef extern from "shapes.h" namespace "shapes":
...@@ -23,6 +26,8 @@ cdef extern from "shapes.h" namespace "shapes": ...@@ -23,6 +26,8 @@ cdef extern from "shapes.h" namespace "shapes":
int height int height
Rectangle() Rectangle()
Rectangle(int, int) Rectangle(int, int)
int method(int)
int method(bint)
cdef cppclass Square(Rectangle): cdef cppclass Square(Rectangle):
int side int side
...@@ -43,6 +48,17 @@ def test_rect_area(w, h): ...@@ -43,6 +48,17 @@ def test_rect_area(w, h):
finally: finally:
del rect 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): def test_square_area(w):
cdef Square *sqr = new Square(w) cdef Square *sqr = new Square(w)
cdef Rectangle *rect = sqr cdef Rectangle *rect = sqr
......
...@@ -23,9 +23,15 @@ namespace shapes { ...@@ -23,9 +23,15 @@ namespace shapes {
this->width = width; this->width = width;
this->height = height; this->height = height;
} }
float area() { return width * height; } float area() { return width * height; }
int width; int width;
int height; int height;
int method(int arg) {
return width * height + arg;
}
}; };
class Square : public Rectangle 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