Skip to content

Commit 48c73d8

Browse files
lrhncommit-bot@chromium.org
authored andcommitted
Clean up annotations and update @override documentation.
Fixes flutter#43622 Bug: http://dartbug.com/43622 Change-Id: I4adea2995146ecd317d5c90a514cb564afa4f846 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165800 Commit-Queue: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
1 parent b7a3a5f commit 48c73d8

File tree

3 files changed

+59
-104
lines changed

3 files changed

+59
-104
lines changed

pkg/compiler/test/model/cfe_constant_evaluation_test.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,21 @@ const List<TestData> DATA = [
7777
ConstantData(r'"${null}"', 'StringConstant("null")'),
7878
ConstantData('identical', 'FunctionConstant(identical)'),
7979
ConstantData('true ? 0 : 1', 'IntConstant(0)'),
80-
ConstantData('proxy', 'ConstructedConstant(_Proxy())'),
80+
ConstantData('deprecated',
81+
'ConstructedConstant(Deprecated(message=StringConstant("next release")))'),
8182
ConstantData('const [] == null', 'BoolConstant(false)'),
82-
ConstantData('proxy == null', 'BoolConstant(false)'),
83-
ConstantData('proxy != null', 'BoolConstant(true)'),
84-
ConstantData('null == proxy', 'BoolConstant(false)'),
85-
ConstantData('null != proxy', 'BoolConstant(true)'),
86-
ConstantData('true == proxy', 'BoolConstant(false)'),
87-
ConstantData('true != proxy', 'BoolConstant(true)'),
88-
ConstantData('0 == proxy', 'BoolConstant(false)'),
89-
ConstantData('0 != proxy', 'BoolConstant(true)'),
90-
ConstantData('0.5 == proxy', 'BoolConstant(false)'),
91-
ConstantData('0.5 != proxy', 'BoolConstant(true)'),
92-
ConstantData('"" == proxy', 'BoolConstant(false)'),
93-
ConstantData('"" != proxy', 'BoolConstant(true)'),
83+
ConstantData('deprecated == null', 'BoolConstant(false)'),
84+
ConstantData('deprecated != null', 'BoolConstant(true)'),
85+
ConstantData('null == deprecated', 'BoolConstant(false)'),
86+
ConstantData('null != deprecated', 'BoolConstant(true)'),
87+
ConstantData('true == deprecated', 'BoolConstant(false)'),
88+
ConstantData('true != deprecated', 'BoolConstant(true)'),
89+
ConstantData('0 == deprecated', 'BoolConstant(false)'),
90+
ConstantData('0 != deprecated', 'BoolConstant(true)'),
91+
ConstantData('0.5 == deprecated', 'BoolConstant(false)'),
92+
ConstantData('0.5 != deprecated', 'BoolConstant(true)'),
93+
ConstantData('"" == deprecated', 'BoolConstant(false)'),
94+
ConstantData('"" != deprecated', 'BoolConstant(true)'),
9495
ConstantData('Object', 'TypeConstant(Object)'),
9596
ConstantData('null ?? 0', 'IntConstant(0)'),
9697
ConstantData('const <int, int>{0: 1, 0: 2}', 'NonConstant',
@@ -320,7 +321,7 @@ class B extends A {
320321
r'"$integer $string $boolean"', 'StringConstant("5 baz false")'),
321322
ConstantData('integer ? true : false', 'NonConstant',
322323
expectedErrors: 'ConstEvalInvalidType'),
323-
ConstantData(r'"${proxy}"', 'NonConstant',
324+
ConstantData(r'"${deprecated}"', 'NonConstant',
324325
expectedErrors: 'ConstEvalInvalidStringInterpolationOperand'),
325326
ConstantData('0 + string', 'NonConstant',
326327
expectedErrors: 'ConstEvalInvalidType'),
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|3725|5|94|Const constructors can't throw exceptions.
2-
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|7925|5|97|Const constructors can't throw exceptions.
3-
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|939|5|95|Const constructors can't throw exceptions.
4-
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|972|5|94|Const constructors can't throw exceptions.
1+
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|3679|5|94|Const constructors can't throw exceptions.
2+
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|7879|5|97|Const constructors can't throw exceptions.
3+
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|893|5|95|Const constructors can't throw exceptions.
4+
ERROR|COMPILE_TIME_ERROR|CONST_CONSTRUCTOR_THROWS_EXCEPTION|lib/core/core.dart|926|5|94|Const constructors can't throw exceptions.
55
ERROR|COMPILE_TIME_ERROR|INVALID_ASSIGNMENT|lib/_internal/js_dev_runtime/private/interceptors.dart|1358|18|27|A value of type 'double' can't be assigned to a variable of type 'int'.
66
ERROR|COMPILE_TIME_ERROR|RETURN_OF_INVALID_TYPE|lib/_internal/js_dev_runtime/private/interceptors.dart|1225|14|38|A value of type 'double' can't be returned from method '%' because it has a return type of 'JSNumber'.
77
ERROR|COMPILE_TIME_ERROR|RETURN_OF_INVALID_TYPE|lib/_internal/js_dev_runtime/private/interceptors.dart|1227|14|38|A value of type 'double' can't be returned from method '%' because it has a return type of 'JSNumber'.
8-
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|3723|3|5|Only redirecting factory constructors can be declared to be 'const'.
9-
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|7923|3|5|Only redirecting factory constructors can be declared to be 'const'.
10-
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|937|3|5|Only redirecting factory constructors can be declared to be 'const'.
11-
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|970|3|5|Only redirecting factory constructors can be declared to be 'const'.
8+
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|3677|3|5|Only redirecting factory constructors can be declared to be 'const'.
9+
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|7877|3|5|Only redirecting factory constructors can be declared to be 'const'.
10+
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|891|3|5|Only redirecting factory constructors can be declared to be 'const'.
11+
ERROR|SYNTACTIC_ERROR|CONST_FACTORY|lib/core/core.dart|924|3|5|Only redirecting factory constructors can be declared to be 'const'.

sdk/lib/core/annotations.dart

Lines changed: 36 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,32 @@ class _Override {
8686
const _Override();
8787
}
8888

89-
/**
90-
* The annotation `@override` marks an instance member as overriding a
91-
* superclass member with the same name.
92-
*
93-
* The annotation applies to instance methods, getters and setters, and to
94-
* instance fields, where it means that the implicit getter and setter of the
95-
* field is marked as overriding, but the field itself is not.
96-
*
97-
* The intent of the `@override` notation is to catch situations where a
98-
* superclass renames a member, and an independent subclass which used to
99-
* override the member, could silently continue working using the
100-
* superclass implementation.
101-
*
102-
* The editor, or a similar tool aimed at the programmer, may report if no
103-
* declaration of an annotated member is inherited by the class from either a
104-
* superclass or an interface.
105-
*
106-
* Use the `@override` annotation judiciously and only for methods where
107-
* the superclass is not under the programmer's control, the superclass is in a
108-
* different library or package, and it is not considered stable.
109-
* In any case, the use of `@override` is optional.
110-
*
111-
* For example, the annotation is intentionally not used in the Dart platform
112-
* libraries, since they only depend on themselves.
113-
*/
89+
/// Annotation on an instance members which override an interface member.
90+
///
91+
/// Annotations have no effect on the meaning of a Dart program.
92+
/// This annotation is recognized by the Dart analyzer, and it allows the
93+
/// analyzer to provide hints or warnings for some potential problems of an
94+
/// otherwise valid program.
95+
/// As such, the meaning of this annotation is defined by the Dart analyzer.
96+
///
97+
/// The `@override` annotation expresses the intent
98+
/// that a declaration *should* override an interface method,
99+
/// something which is not visible from the declaration itself.
100+
/// This extra information allows the analyzer to provide a warning
101+
/// when that intent is not satisfied,
102+
/// where a member is intended to override a superclass member or
103+
/// implement an interface member, but fails to do so.
104+
/// Such a situation can arise if a member name is mistyped,
105+
/// or if the superclass renames the member.
106+
///
107+
/// The `@override` annotation applies to instance methods, instance getters,
108+
/// instance setters and instance variables (fields).
109+
/// When applied to an instance variable,
110+
/// it means that the variable's implicit getter and setter (if any)
111+
/// are marked as overriding. It has no effect on the variable itself.
112+
///
113+
/// Further [lints](https://dart-lang.github.io/linter/lints/)
114+
/// can be used to enable more warnings based on `@override` annotations.
114115
const Object override = _Override();
115116

116117
/**
@@ -127,64 +128,16 @@ class Provisional {
127128
/**
128129
* An annotation that was used during development of Dart 2.
129130
*
130-
* Should not be used any more.
131+
* The annotation has no effect, and will be removed.
131132
*/
132133
@deprecated
133134
const Null provisional = null;
134135

135-
class _Proxy {
136-
const _Proxy();
137-
}
138-
139-
/**
140-
* This annotation is deprecated and will be removed in Dart 2.
141-
*
142-
* Dart 2 has a more restrictive type system than Dart 1, and it requires
143-
* method access to be either through a known interface or by using
144-
* dynamic invocations. The original intent of `@proxy` (to implement a class
145-
* that isn't known statically, as documented at the end of this text),
146-
* is not supported by Dart 2.
147-
* To continue to perform dynamic invocations on an object,
148-
* it should be accessed through a reference of type `dynamic`.
149-
*
150-
* The annotation `@proxy` marks a class as implementing members dynamically
151-
* through `noSuchMethod`.
152-
*
153-
* The annotation applies to any class. It is inherited by subclasses from both
154-
* superclass and interfaces.
155-
*
156-
* If a class is annotated with `@proxy`, or it implements any class that is
157-
* annotated, then all member accesses are allowed on an object of that type.
158-
* As such, it is not a static type warning to access any member of the object
159-
* which is not implemented by the class, or to call a method with a different
160-
* number of parameters than it is declared with.
161-
*
162-
* The annotation does not change which classes the annotated class implements,
163-
* and does not prevent static warnings for assigning an object to a variable
164-
* with a static type not implemented by the object.
165-
*
166-
* The suppression of warnings only affect static type warnings about
167-
* member access.
168-
* The runtime type of the object is unaffected.
169-
* It is not considered to implement any special interfaces,
170-
* so assigning it to a typed variable may fail in checked mode,
171-
* and testing it with the `is` operator
172-
* will only return true for types it actually implements or extends.
173-
* Accessing a member which isn't implemented by the class
174-
* will cause the `noSuchMethod` method to be called normally,
175-
* the `@proxy` annotation merely states the intent to handle (some of) those
176-
* `noSuchMethod` calls gracefully.
177-
*
178-
* A class that marked as `@proxy` should override the `noSuchMethod`
179-
* declared on [Object].
180-
*
181-
* The intent of the `@proxy` notation is to create objects that implement a
182-
* type (or multiple types) that are not known at compile time. If the types
183-
* are known at compile time, a class can be written that implements these
184-
* types.
185-
*/
136+
/// This annotation was used in Dart prior to version 2.
137+
///
138+
/// The annotation has no effect, and will be removed.
186139
@deprecated
187-
const Object proxy = _Proxy();
140+
const Null proxy = null;
188141

189142
/**
190143
* A hint to tools.
@@ -203,7 +156,8 @@ const Object proxy = _Proxy();
203156
* A tool may recognize unprefixed names as well, if they would recognize that
204157
* name with their own prefix in front.
205158
*
206-
* If the hint can be parameterized, an extra [options] object can be added as well.
159+
* If the hint can be parameterized,
160+
* an extra [options] object can be added as well.
207161
*
208162
* For example:
209163
*
@@ -215,9 +169,9 @@ const Object proxy = _Proxy();
215169
* void foo() { }
216170
* ```
217171
*
218-
* Here class Foo is annotated with a Tool specific pragma 'pragma-name' and
219-
* function foo is annotated with a pragma 'other-pragma' specific to OtherTool.
220-
*
172+
* Here class `Foo` is annotated with a Tool specific pragma 'pragma-name' and
173+
* function `foo` is annotated with a pragma 'other-pragma'
174+
* specific to OtherTool.
221175
*/
222176
@pragma('vm:entry-point')
223177
class pragma {

0 commit comments

Comments
 (0)