-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
6630d75
commit 42f8a33
Showing
5 changed files
with
103 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |