Skip to content

Commit 4d524b9

Browse files
committed
Complain when multiple methods in the same scope match a call
Issue #1227
1 parent 7185ea3 commit 4d524b9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/comp/middle/typeck.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,9 +1460,8 @@ fn check_expr_with(fcx: @fn_ctxt, expr: @ast::expr, expected: ty::t) -> bool {
14601460
ret check_expr_with_unifier(fcx, expr, demand::simple, expected);
14611461
}
14621462

1463-
// FIXME[impl] notice/resolve conflicts
14641463
fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
1465-
name: ast::ident, ty: ty::t)
1464+
name: ast::ident, ty: ty::t, sp: span)
14661465
-> option::t<{method: @resolve::method_info, ids: [int]}> {
14671466
let result = none;
14681467
std::list::iter(isc) {|impls|
@@ -1488,8 +1487,13 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
14881487
} else { {ids: [], ty: self_ty} };
14891488
alt unify::unify(fcx, ty, self_ty) {
14901489
ures_ok(_) {
1491-
result = some({method: m, ids: ids});
1492-
ret;
1490+
if option::is_some(result) {
1491+
// FIXME[impl] score specificity to resolve ambiguity?
1492+
fcx.ccx.tcx.sess.span_err(
1493+
sp, "multiple applicable methods in scope");
1494+
} else {
1495+
result = some({method: m, ids: ids});
1496+
}
14931497
}
14941498
_ {}
14951499
}
@@ -2159,7 +2163,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21592163
}
21602164
if !handled {
21612165
let iscope = fcx.ccx.impl_map.get(expr.id);
2162-
alt lookup_method(fcx, iscope, field, expr_t) {
2166+
alt lookup_method(fcx, iscope, field, expr_t, expr.span) {
21632167
some({method, ids}) {
21642168
let fty = if method.did.crate == ast::local_crate {
21652169
alt tcx.items.get(method.did.node) {

0 commit comments

Comments
 (0)