follow up for #25578, add @checked to package:meta

R=pquitslund@google.com

Review URL: https://codereview.chromium.org/2334413002 .
This commit is contained in:
John Messerly 2016-09-13 17:26:24 -07:00
parent 743fe92c49
commit 05e945d1c0
4 changed files with 53 additions and 1 deletions

View file

@ -39,6 +39,25 @@
}
```
* New feature - use `@checked` to override a method and tighten a parameter
type (SDK issue [25578](https://github.com/dart-lang/sdk/issues/25578)).
```dart
import 'package:meta/meta.dart' show checked;
class View {
addChild(View v) {}
}
class MyView extends View {
// this override is legal, it will check at runtime if we actually
// got a MyView.
addChild(@checked MyView v) {}
}
main() {
dynamic mv = new MyView();
mv.addChild(new View()); // runtime error
}
```
## 1.19.0
### Language changes

View file

@ -1,3 +1,23 @@
## 1.0.3
* Introduce `@checked` to override a method and tighten a parameter
type (SDK issue [25578](https://github.com/dart-lang/sdk/issues/25578)).
```dart
import 'package:meta/meta.dart' show checked;
class View {
addChild(View v) {}
}
class MyView extends View {
// this override is legal, it will check at runtime if we actually
// got a MyView.
addChild(@checked MyView v) {}
}
main() {
dynamic mv = new MyView();
mv.addChild(new View()); // runtime error
}
```
## 1.0.2
* Introduce `@visibleForTesting` annotation for declarations that may be referenced only in the library or in a test.

View file

@ -128,6 +128,19 @@ class Required {
const Required([this.reason]);
}
/// Used to annotate a parameter of an instance method that overrides another
/// method.
///
/// Indicates that this parameter may have a tighter type than the parameter on
/// its superclass. The actual argument will be checked at runtime to ensure it
/// is a subtype of the overridden parameter type.
const _Checked checked = const _Checked();
class _Checked {
const _Checked();
}
class _Factory {
const _Factory();
}

View file

@ -1,5 +1,5 @@
name: meta
version: 1.0.2
version: 1.0.3
author: Dart Team <misc@dartlang.org>
homepage: http://www.dartlang.org
description: >