diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index a9f23887075..9a6fd4bbd92 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -1878,14 +1878,21 @@ mod unify { ufind::grow(cx.vb.sets, uint::max(set_a, set_b) + 1u); auto root_a = ufind::find(cx.vb.sets, set_a); auto root_b = ufind::find(cx.vb.sets, set_b); - ufind::union(cx.vb.sets, set_a, set_b); - auto root_c = ufind::find(cx.vb.sets, set_a); + + auto replace_type = bind fn (&@ctxt cx, t t, uint set_a, uint set_b) { + ufind::union(cx.vb.sets, set_a, set_b); + let uint root_c = ufind::find(cx.vb.sets, set_a); + smallintmap::insert[t](cx.vb.types, root_c, t); + } (_, _, set_a, set_b); + alt (smallintmap::find[t](cx.vb.types, root_a)) { case (none[t]) { alt (smallintmap::find[t](cx.vb.types, root_b)) { - case (none[t]) { ret unres_ok; } + case (none[t]) { + ufind::union(cx.vb.sets, set_a, set_b); + ret unres_ok; } case (some[t](?t_b)) { - smallintmap::insert[t](cx.vb.types, root_c, t_b); + replace_type(cx, t_b); ret unres_ok; } } @@ -1893,17 +1900,18 @@ mod unify { case (some[t](?t_a)) { alt (smallintmap::find[t](cx.vb.types, root_b)) { case (none[t]) { - smallintmap::insert[t](cx.vb.types, root_c, t_a); + replace_type(cx, t_a); ret unres_ok; } case (some[t](?t_b)) { alt (unify_step(cx, t_a, t_b)) { case (ures_ok(?t_c)) { - smallintmap::insert[t](cx.vb.types, root_c, - t_c); + replace_type(cx, t_c); ret unres_ok; } - case (ures_err(?terr)) { ret unres_err(terr); } + case (ures_err(?terr)) { + ret unres_err(terr); + } } } } diff --git a/src/test/compile-fail/type-mismatch.rs b/src/test/compile-fail/type-mismatch.rs new file mode 100644 index 00000000000..1ab8a1334b0 --- /dev/null +++ b/src/test/compile-fail/type-mismatch.rs @@ -0,0 +1,9 @@ +// xfail-stage0 +// error-pattern:expected bool but found int +// issue #516 + +fn main() { + auto x = true; + auto y = 1; + auto z = x + y; +} \ No newline at end of file