aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-01-04 16:52:06 -0800
committerPatrick Walton <[email protected]>2011-01-04 16:53:28 -0800
commitb7d2fe57cfa7d260838832ad8c301a946206c16d (patch)
tree5299a114fcab53e0e71d1f41b84279db42fe6e37 /src/comp
parentCorrect function pointer type in closure. (diff)
downloadrust-b7d2fe57cfa7d260838832ad8c301a946206c16d.tar.xz
rust-b7d2fe57cfa7d260838832ad8c301a946206c16d.zip
rustc: Allow the type unification handler to handle both expected and actual param types
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/ty.rs12
-rw-r--r--src/comp/middle/typeck.rs12
2 files changed, 20 insertions, 4 deletions
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);