Skip to content

Commit 0eac640

Browse files
committed
Swap the expected/actual for typechecking fields of updated records
In 'rec(a = b with c)', if a exists in c then the expected type for b is the type of c.
1 parent 05954f3 commit 0eac640

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/comp/middle/typeck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,8 +2120,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
21202120
auto found = false;
21212121
for (ty::field bf in base_fields) {
21222122
if (str::eq(f.ident, bf.ident)) {
2123-
demand::simple(fcx, expr.span, f.mt.ty,
2124-
bf.mt.ty);
2123+
demand::simple(fcx, expr.span, bf.mt.ty,
2124+
f.mt.ty);
21252125
found = true;
21262126
}
21272127
}

src/test/compile-fail/rec-extend.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// xfail-stage0
2+
// error-pattern:expected int but found bool
3+
4+
fn main() {
5+
6+
auto a = rec(foo = 0);
7+
8+
auto b = rec(foo = true with a);
9+
}

0 commit comments

Comments
 (0)