Skip to content

Commit d5e2791

Browse files
authored
Add docs for new @mustBeConst diagnostic (#5689)
1 parent 976ed7e commit d5e2791

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/content/tools/diagnostic-messages.md

+34
Original file line numberDiff line numberDiff line change
@@ -15089,6 +15089,40 @@ class C {
1508915089
}
1509015090
```
1509115091

15092+
### non_const_argument_for_const_parameter
15093+
15094+
_Argument '{0}' must be a constant._
15095+
15096+
#### Description
15097+
15098+
The analyzer produces this diagnostic when a parameter is
15099+
annotated with the `@mustBeConst` annotation and the
15100+
corresponding argument is not a constant expression.
15101+
15102+
#### Example
15103+
15104+
The following code produces this diagnostic on the invocation of
15105+
the function `f` because the value of the argument passed to the
15106+
function `g` isn't a constant:
15107+
15108+
```dart
15109+
import 'package:meta/meta.dart' show mustBeConst;
15110+
int f(int value) => g([!value!]);
15111+
int g(@mustBeConst int value) => value + 1;
15112+
```
15113+
15114+
#### Common fixes
15115+
15116+
If a suitable constant is available to use, then replace the argument
15117+
with a constant:
15118+
15119+
```dart
15120+
import 'package:meta/meta.dart' show mustBeConst;
15121+
const v = 3;
15122+
int f() => g(v);
15123+
int g(@mustBeConst int value) => value + 1;
15124+
```
15125+
1509215126
### non_const_call_to_literal_constructor
1509315127

1509415128
_This instance creation must be 'const', because the {0} constructor is marked

0 commit comments

Comments
 (0)