Skip to content

Commit d2b7ea8

Browse files
committed
rustc: Don't commit unification changes until unify succeeds
This is so that subsequent reports about type mismatches get the types correct. Issue #516
1 parent d9b56ec commit d2b7ea8

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/comp/middle/ty.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -1878,32 +1878,40 @@ mod unify {
18781878
ufind::grow(cx.vb.sets, uint::max(set_a, set_b) + 1u);
18791879
auto root_a = ufind::find(cx.vb.sets, set_a);
18801880
auto root_b = ufind::find(cx.vb.sets, set_b);
1881-
ufind::union(cx.vb.sets, set_a, set_b);
1882-
auto root_c = ufind::find(cx.vb.sets, set_a);
1881+
1882+
auto replace_type = bind fn (&@ctxt cx, t t, uint set_a, uint set_b) {
1883+
ufind::union(cx.vb.sets, set_a, set_b);
1884+
let uint root_c = ufind::find(cx.vb.sets, set_a);
1885+
smallintmap::insert[t](cx.vb.types, root_c, t);
1886+
} (_, _, set_a, set_b);
1887+
18831888
alt (smallintmap::find[t](cx.vb.types, root_a)) {
18841889
case (none[t]) {
18851890
alt (smallintmap::find[t](cx.vb.types, root_b)) {
1886-
case (none[t]) { ret unres_ok; }
1891+
case (none[t]) {
1892+
ufind::union(cx.vb.sets, set_a, set_b);
1893+
ret unres_ok; }
18871894
case (some[t](?t_b)) {
1888-
smallintmap::insert[t](cx.vb.types, root_c, t_b);
1895+
replace_type(cx, t_b);
18891896
ret unres_ok;
18901897
}
18911898
}
18921899
}
18931900
case (some[t](?t_a)) {
18941901
alt (smallintmap::find[t](cx.vb.types, root_b)) {
18951902
case (none[t]) {
1896-
smallintmap::insert[t](cx.vb.types, root_c, t_a);
1903+
replace_type(cx, t_a);
18971904
ret unres_ok;
18981905
}
18991906
case (some[t](?t_b)) {
19001907
alt (unify_step(cx, t_a, t_b)) {
19011908
case (ures_ok(?t_c)) {
1902-
smallintmap::insert[t](cx.vb.types, root_c,
1903-
t_c);
1909+
replace_type(cx, t_c);
19041910
ret unres_ok;
19051911
}
1906-
case (ures_err(?terr)) { ret unres_err(terr); }
1912+
case (ures_err(?terr)) {
1913+
ret unres_err(terr);
1914+
}
19071915
}
19081916
}
19091917
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-stage0
2+
// error-pattern:expected bool but found int
3+
// issue #516
4+
5+
fn main() {
6+
auto x = true;
7+
auto y = 1;
8+
auto z = x + y;
9+
}

0 commit comments

Comments
 (0)