Skip to content

Commit b83a4af

Browse files
brsongraydon
authored andcommitted
Fix the typechecking for expr_send and expr_recv
1 parent 4ce4d88 commit b83a4af

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/comp/middle/typeck.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,18 +1831,48 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
18311831
}
18321832

18331833
case (ast.expr_send(?lhs, ?rhs, _)) {
1834-
auto checked = check_assignment_like(fcx, lhs, rhs);
1835-
auto newexpr = ast.expr_send(checked._0,
1836-
checked._1,
1837-
checked._2);
1834+
auto lhs_0 = check_expr(fcx, lhs);
1835+
auto rhs_0 = check_expr(fcx, rhs);
1836+
auto rhs_t = expr_ty(rhs_0);
1837+
1838+
auto chan_t = plain_ty(ty.ty_chan(rhs_t));
1839+
auto lhs_1 = demand_expr(fcx, chan_t, lhs_0);
1840+
auto item_t;
1841+
alt (expr_ty(lhs_1).struct) {
1842+
case (ty.ty_chan(?it)) {
1843+
item_t = it;
1844+
}
1845+
case (_) {
1846+
fail;
1847+
}
1848+
}
1849+
auto rhs_1 = demand_expr(fcx, item_t, rhs_0);
1850+
1851+
auto ann = ast.ann_type(chan_t, none[vec[@ty.t]]);
1852+
auto newexpr = ast.expr_send(lhs_1, rhs_1, ann);
18381853
ret @fold.respan[ast.expr_](expr.span, newexpr);
18391854
}
18401855

18411856
case (ast.expr_recv(?lhs, ?rhs, _)) {
1842-
auto checked = check_assignment_like(fcx, lhs, rhs);
1843-
auto newexpr = ast.expr_recv(checked._0,
1844-
checked._1,
1845-
checked._2);
1857+
auto lhs_0 = check_expr(fcx, lhs);
1858+
auto rhs_0 = check_expr(fcx, rhs);
1859+
auto lhs_t1 = expr_ty(lhs_0);
1860+
1861+
auto port_t = plain_ty(ty.ty_port(lhs_t1));
1862+
auto rhs_1 = demand_expr(fcx, port_t, rhs_0);
1863+
auto item_t;
1864+
alt (expr_ty(rhs_0).struct) {
1865+
case (ty.ty_port(?it)) {
1866+
item_t = it;
1867+
}
1868+
case (_) {
1869+
fail;
1870+
}
1871+
}
1872+
auto lhs_1 = demand_expr(fcx, item_t, lhs_0);
1873+
1874+
auto ann = ast.ann_type(item_t, none[vec[@ty.t]]);
1875+
auto newexpr = ast.expr_recv(lhs_1, rhs_1, ann);
18461876
ret @fold.respan[ast.expr_](expr.span, newexpr);
18471877
}
18481878

0 commit comments

Comments
 (0)