From b7d2fe57cfa7d260838832ad8c301a946206c16d Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 4 Jan 2011 16:52:06 -0800 Subject: rustc: Allow the type unification handler to handle both expected and actual param types --- src/comp/middle/ty.rs | 12 ++++++++---- src/comp/middle/typeck.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/comp') diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index d4658080..ddb7b7a9 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -51,6 +51,8 @@ type unify_handler = obj { fn record_local(ast.def_id id, @t ty); fn unify_expected_param(ast.def_id id, @t expected, @t actual) -> unify_result; + fn unify_actual_param(ast.def_id id, @t expected, @t actual) + -> unify_result; }; tag type_err { @@ -854,9 +856,9 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler) // TODO: rewrite this using tuple pattern matching when available, to // avoid all this rightward drift and spikiness. - // If the RHS is a variable type, then just do the appropriate - // binding. alt (actual.struct) { + // If the RHS is a variable type, then just do the appropriate + // binding. case (ty.ty_var(?actual_id)) { alt (bindings.find(actual_id)) { case (some[@ty.t](?actual_ty)) { @@ -885,6 +887,9 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler) } ret result; } + case (ty.ty_param(?actual_id)) { + ret handler.unify_actual_param(actual_id, expected, actual); + } case (_) { /* empty */ } } @@ -1131,8 +1136,7 @@ fn unify(@ty.t expected, @ty.t actual, &unify_handler handler) } case (ty.ty_param(?expected_id)) { - ret handler.unify_expected_param(expected_id, - expected, + ret handler.unify_expected_param(expected_id, expected, actual); } } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index ab82537b..d1e34e7a 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -509,6 +509,18 @@ fn unify(&@fn_ctxt fcx, @ty.t expected, @ty.t actual) -> ty.unify_result { } ret ty.ures_err(ty.terr_mismatch, expected, actual); } + fn unify_actual_param(ast.def_id id, @ty.t expected, @ty.t actual) + -> ty.unify_result { + alt (expected.struct) { + case (ty.ty_param(?expected_id)) { + if (id._0 == expected_id._0 && id._1 == expected_id._1) { + ret ty.ures_ok(actual); + } + } + case (_) { /* fall through */ } + } + ret ty.ures_err(ty.terr_mismatch, expected, actual); + } } auto handler = unify_handler(fcx); -- cgit v1.2.3