Chromium Code Reviews| Index: pkg/meta/lib/meta.dart |
| diff --git a/pkg/meta/lib/meta.dart b/pkg/meta/lib/meta.dart |
| index 99a3924683d74e9aa7e2014f28350b92e86d901c..6a53dd86c0c05315b80b460ad6f33aed48999f51 100644 |
| --- a/pkg/meta/lib/meta.dart |
| +++ b/pkg/meta/lib/meta.dart |
| @@ -18,6 +18,31 @@ |
| /// in the language tour. |
| library meta; |
| +/// Used to annotate a function `f`. Indicates that `f` always throws an |
| +/// exception. |
| +/// |
| +/// Tools, such as the analyzer, can use this to understand whether a block of |
| +/// code "exits". For example: |
| +/// |
| +/// ```dart |
| +/// @alwaysThrows toss() { throw 'Thrown'; } |
| +/// |
| +/// int fn(bool b) { |
| +/// if (b) { |
| +/// return 0; |
| +/// } else { |
| +/// toss(); |
| +/// print("Hello."); |
| +/// } |
| +/// } |
| +/// ``` |
| +/// |
| +/// Without the annotation on `toss`, it would look as though `fn` doesn't |
| +/// always return a / value. The annotation shows that `fn` does always exit. In |
|
Brian Wilkerson
2016/07/21 15:39:25
Not sure why there's a slash on either this line o
|
| +/// addition, the / annotation reveals that any statements following a call to |
| +/// `toss` (like the `print` call) are dead code. |
| +const _AlwaysThrows alwaysThrows = const _AlwaysThrows(); |
|
Brian Wilkerson
2016/07/21 15:39:25
There are two ways in which this annotation can ad
|
| + |
| /// Used to annotate an instance or static method `m`. Indicates that `m` must |
| /// either be abstract or must return a newly allocated object or `null`. In |
| /// addition, every method that either implements or overrides `m` is implicitly |
| @@ -116,6 +141,10 @@ class Required { |
| const Required([this.reason]); |
| } |
| +class _AlwaysThrows { |
| + const _AlwaysThrows(); |
| +} |
| + |
| class _Factory { |
| const _Factory(); |
| } |