diff --git a/src/content/tools/diagnostic-messages.md b/src/content/tools/diagnostic-messages.md index 4f1483d949..2755713e6a 100644 --- a/src/content/tools/diagnostic-messages.md +++ b/src/content/tools/diagnostic-messages.md @@ -15089,6 +15089,40 @@ class C { } ``` +### non_const_argument_for_const_parameter + +_Argument '{0}' must be a constant._ + +#### Description + +The analyzer produces this diagnostic when a parameter is +annotated with the `@mustBeConst` annotation and the +corresponding argument is not a constant expression. + +#### Example + +The following code produces this diagnostic on the invocation of +the function `f` because the value of the argument passed to the +function `g` isn't a constant: + +```dart +import 'package:meta/meta.dart' show mustBeConst; +int f(int value) => g([!value!]); +int g(@mustBeConst int value) => value + 1; +``` + +#### Common fixes + +If a suitable constant is available to use, then replace the argument +with a constant: + +```dart +import 'package:meta/meta.dart' show mustBeConst; +const v = 3; +int f() => g(v); +int g(@mustBeConst int value) => value + 1; +``` + ### non_const_call_to_literal_constructor _This instance creation must be 'const', because the {0} constructor is marked