Print out a more helpful type error message for do-blocks/for-loops
If a do-block body has the wrong type, or a for-loop body has a non-() type, suggest that the user might have meant the other one. Closes #2817 r=brson
This commit is contained in:
parent
6630d75a1d
commit
42f8a3366a
5 changed files with 103 additions and 30 deletions
|
|
@ -1,7 +1,5 @@
|
|||
// error-pattern:mismatched types: expected `()` but found `bool`
|
||||
|
||||
fn main() {
|
||||
for vec::each(~[0]) |_i| {
|
||||
for vec::each(~[0]) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
true
|
||||
}
|
||||
}
|
||||
16
src/test/compile-fail/issue-2817-2.rs
Normal file
16
src/test/compile-fail/issue-2817-2.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
fn not_bool(f: fn(int) -> ~str) {}
|
||||
|
||||
fn main() {
|
||||
for uint::range(0, 100000) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
false
|
||||
};
|
||||
for not_bool |_i| { //~ ERROR a `loop` function's last argument should return `bool`
|
||||
//~^ ERROR A for-loop body must return (), but
|
||||
~"hi"
|
||||
};
|
||||
for uint::range(0, 100000) |_i| { //~ ERROR A for-loop body must return (), but
|
||||
~"hi"
|
||||
};
|
||||
for not_bool() |_i| { //~ ERROR a `loop` function's last argument
|
||||
};
|
||||
}
|
||||
15
src/test/compile-fail/issue-2817.rs
Normal file
15
src/test/compile-fail/issue-2817.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
fn uuid() -> uint { fail; }
|
||||
|
||||
fn from_str(s: ~str) -> uint { fail; }
|
||||
fn to_str(u: uint) -> ~str { fail; }
|
||||
fn uuid_random() -> uint { fail; }
|
||||
|
||||
fn main() {
|
||||
do uint::range(0, 100000) |_i| { //~ ERROR Do-block body must return bool, but
|
||||
}
|
||||
// should get a more general message if the callback
|
||||
// doesn't return nil
|
||||
do uint::range(0, 100000) |_i| { //~ ERROR mismatched types
|
||||
~"str"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue