Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for new @mustBeConst diagnostic #5689

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/content/tools/diagnostic-messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down