Skip to content

Commit b620be9

Browse files
committed
Typecheck @[] correctly
Previously, if you wrote let @vec[int] foo = @[]; that would be a type error. That didn't seem right, so I changed pushdown to unify the inner type in an unop application with the argument type of the operator type.
1 parent 2505a23 commit b620be9

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/comp/middle/typeck.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,31 @@ mod Pushdown {
13171317
auto t = Demand::autoderef(scx, e.span, expected,
13181318
ann_to_type(scx.fcx.ccx.tcx.node_types, ann), adk);
13191319
write::ty_only_fixup(scx, ann.id, t);
1320+
1321+
/* The following is a bit special-cased, but takes care of
1322+
the case where we say let @vec[whatever] v = @[]; */
1323+
auto inner_ty = t;
1324+
alt (uop) {
1325+
case (ast::box(?mut)) {
1326+
alt (struct(scx.fcx.ccx.tcx, t)) {
1327+
case (ty::ty_box(?inner)) { inner_ty = inner.ty; }
1328+
case (_) {
1329+
scx.fcx.ccx.tcx.sess.span_err(e.span,
1330+
"Expecting an application of box"
1331+
+ " to have a box type");
1332+
}
1333+
}
1334+
}
1335+
case (ast::deref) {
1336+
inner_ty = ty::mk_box(scx.fcx.ccx.tcx,
1337+
// maybe_mut should work because it'll unify with
1338+
// the existing type?
1339+
rec(ty=t, mut=ast::maybe_mut));
1340+
}
1341+
case (_) { inner_ty = strip_boxes(scx.fcx.ccx.tcx, t); }
1342+
}
1343+
1344+
pushdown_expr(scx, inner_ty, sube);
13201345
}
13211346
case (ast::expr_lit(?lit, ?ann)) {
13221347
auto t = Demand::simple(scx, e.span, expected,

src/test/compile-fail/vector-no-ann-2.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/test/run-pass/vector-no-ann-2.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() -> () {
2+
let @vec[uint] quux = @[];
3+
}

0 commit comments

Comments
 (0)