Skip to content

Commit

Permalink
follow up for #25578, add @checked to package:meta
Browse files Browse the repository at this point in the history
R=pquitslund@google.com

Review URL: https://codereview.chromium.org/2334413002 .
  • Loading branch information
John Messerly committed Sep 14, 2016
1 parent 743fe92 commit 05e945d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions pkg/meta/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
13 changes: 13 additions & 0 deletions pkg/meta/lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/meta/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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: >
Expand Down

0 comments on commit 05e945d

Please sign in to comment.