Do not consider ty_bot to be a "resolved type".
Fixes #2149. Fixes #2150. Fixes #2151.
This commit is contained in:
parent
7aaa120bcc
commit
1e42c9a367
8 changed files with 51 additions and 8 deletions
|
@ -232,8 +232,10 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
|
|||
// Type tests
|
||||
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
|
||||
alt infer::resolve_type_structure(fcx.infcx, tp) {
|
||||
result::ok(typ_s) { ret typ_s; }
|
||||
result::err(_) {
|
||||
// note: the bot type doesn't count as resolved; it's what we use when
|
||||
// there is no information about a variable.
|
||||
result::ok(t_s) if !ty::type_is_bot(t_s) { ret t_s; }
|
||||
_ {
|
||||
fcx.ccx.tcx.sess.span_fatal
|
||||
(sp, "the type of this value must be known in this context");
|
||||
}
|
||||
|
|
14
src/test/compile-fail/issue-2149.rs
Normal file
14
src/test/compile-fail/issue-2149.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
iface monad<A> {
|
||||
fn bind<B>(fn(A) -> self<B>);
|
||||
}
|
||||
impl monad<A> of monad<A> for [A] {
|
||||
fn bind<B>(f: fn(A) -> [B]) {
|
||||
let mut r = fail;
|
||||
for self.each {|elt| r += f(elt); }
|
||||
//!^ WARNING unreachable expression
|
||||
//!^^ ERROR the type of this value must be known
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
["hi"].bind {|x| [x] };
|
||||
}
|
8
src/test/compile-fail/issue-2150.rs
Normal file
8
src/test/compile-fail/issue-2150.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
fn fail_len(v: [const int]) -> uint {
|
||||
let mut i = fail;
|
||||
for v.each {|x| i += 1u; }
|
||||
//!^ WARNING unreachable statement
|
||||
//!^^ ERROR the type of this value must be known
|
||||
ret i;
|
||||
}
|
||||
fn main() {}
|
6
src/test/compile-fail/issue-2151.rs
Normal file
6
src/test/compile-fail/issue-2151.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
fn main() {
|
||||
vec::iter(fail) {|i|
|
||||
log (debug, i * 2);
|
||||
//!^ ERROR the type of this value must be known
|
||||
};
|
||||
}
|
14
src/test/compile-fail/unreachable-code-1.rs
Normal file
14
src/test/compile-fail/unreachable-code-1.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// xfail-pretty
|
||||
|
||||
fn id(x: bool) -> bool { x }
|
||||
|
||||
fn call_id() {
|
||||
let c <- fail;
|
||||
id(c); //! WARNING unreachable statement
|
||||
}
|
||||
|
||||
fn call_id_3() { id(ret) && id(ret); }
|
||||
//!^ ERROR the type of this value must be known
|
||||
|
||||
fn main() {
|
||||
}
|
|
@ -4,5 +4,7 @@
|
|||
// preserved. They are needed to disambiguate `{ret n+1}; - 0` from
|
||||
// `({ret n+1}-0)`.
|
||||
|
||||
fn wsucc(n: int) -> int { ({ ret n + 1 }) - 0; }
|
||||
fn id(f: fn() -> int) -> int { f() }
|
||||
|
||||
fn wsucc(n: int) -> int { (id {|| 1 }) - 0 }
|
||||
fn main() { }
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
fn wsucc(n: int) -> int { ({ ret n + 1 } + 0); }
|
||||
fn wsucc(n: int) -> int { 0 + { ret n + 1 } }
|
||||
fn main() { }
|
||||
|
|
|
@ -9,8 +9,6 @@ fn call_id() {
|
|||
|
||||
fn call_id_2() { id(true) && id(ret); }
|
||||
|
||||
fn call_id_3() { id(ret) && id(ret); }
|
||||
|
||||
fn call_id_4() { while id(ret) { } }
|
||||
|
||||
fn bind_id_1() { bind id(fail); }
|
||||
|
@ -27,7 +25,7 @@ fn log_break() { loop { log(error, break); } }
|
|||
|
||||
fn log_cont() { do { log(error, cont); } while false }
|
||||
|
||||
fn ret_ret() -> int { ret (ret 2) + 3; }
|
||||
fn ret_ret() -> int { ret 3 + (ret 2); }
|
||||
|
||||
fn ret_guard() {
|
||||
alt check 2 {
|
||||
|
@ -53,7 +51,6 @@ fn main() {
|
|||
ret_ret();
|
||||
log_ret();
|
||||
call_id_2();
|
||||
call_id_3();
|
||||
call_id_4();
|
||||
bind_id_2();
|
||||
ret_guard();
|
||||
|
|
Loading…
Add table
Reference in a new issue