Skip to content

Commit 1e42c9a

Browse files
committed
Do not consider ty_bot to be a "resolved type".
Fixes #2149. Fixes #2150. Fixes #2151.
1 parent 7aaa120 commit 1e42c9a

File tree

8 files changed

+51
-8
lines changed

8 files changed

+51
-8
lines changed

src/rustc/middle/typeck.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,10 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
232232
// Type tests
233233
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
234234
alt infer::resolve_type_structure(fcx.infcx, tp) {
235-
result::ok(typ_s) { ret typ_s; }
236-
result::err(_) {
235+
// note: the bot type doesn't count as resolved; it's what we use when
236+
// there is no information about a variable.
237+
result::ok(t_s) if !ty::type_is_bot(t_s) { ret t_s; }
238+
_ {
237239
fcx.ccx.tcx.sess.span_fatal
238240
(sp, "the type of this value must be known in this context");
239241
}

src/test/compile-fail/issue-2149.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
iface monad<A> {
2+
fn bind<B>(fn(A) -> self<B>);
3+
}
4+
impl monad<A> of monad<A> for [A] {
5+
fn bind<B>(f: fn(A) -> [B]) {
6+
let mut r = fail;
7+
for self.each {|elt| r += f(elt); }
8+
//!^ WARNING unreachable expression
9+
//!^^ ERROR the type of this value must be known
10+
}
11+
}
12+
fn main() {
13+
["hi"].bind {|x| [x] };
14+
}

src/test/compile-fail/issue-2150.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn fail_len(v: [const int]) -> uint {
2+
let mut i = fail;
3+
for v.each {|x| i += 1u; }
4+
//!^ WARNING unreachable statement
5+
//!^^ ERROR the type of this value must be known
6+
ret i;
7+
}
8+
fn main() {}

src/test/compile-fail/issue-2151.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
vec::iter(fail) {|i|
3+
log (debug, i * 2);
4+
//!^ ERROR the type of this value must be known
5+
};
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// xfail-pretty
2+
3+
fn id(x: bool) -> bool { x }
4+
5+
fn call_id() {
6+
let c <- fail;
7+
id(c); //! WARNING unreachable statement
8+
}
9+
10+
fn call_id_3() { id(ret) && id(ret); }
11+
//!^ ERROR the type of this value must be known
12+
13+
fn main() {
14+
}

src/test/pretty/disamb-stmt-expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
// preserved. They are needed to disambiguate `{ret n+1}; - 0` from
55
// `({ret n+1}-0)`.
66

7-
fn wsucc(n: int) -> int { ({ ret n + 1 }) - 0; }
7+
fn id(f: fn() -> int) -> int { f() }
8+
9+
fn wsucc(n: int) -> int { (id {|| 1 }) - 0 }
810
fn main() { }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
fn wsucc(n: int) -> int { ({ ret n + 1 } + 0); }
1+
fn wsucc(n: int) -> int { 0 + { ret n + 1 } }
22
fn main() { }

src/test/run-pass/unreachable-code.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ fn call_id() {
99

1010
fn call_id_2() { id(true) && id(ret); }
1111

12-
fn call_id_3() { id(ret) && id(ret); }
13-
1412
fn call_id_4() { while id(ret) { } }
1513

1614
fn bind_id_1() { bind id(fail); }
@@ -27,7 +25,7 @@ fn log_break() { loop { log(error, break); } }
2725

2826
fn log_cont() { do { log(error, cont); } while false }
2927

30-
fn ret_ret() -> int { ret (ret 2) + 3; }
28+
fn ret_ret() -> int { ret 3 + (ret 2); }
3129

3230
fn ret_guard() {
3331
alt check 2 {
@@ -53,7 +51,6 @@ fn main() {
5351
ret_ret();
5452
log_ret();
5553
call_id_2();
56-
call_id_3();
5754
call_id_4();
5855
bind_id_2();
5956
ret_guard();

0 commit comments

Comments
 (0)