blob: c7bb24f031fd3253a11a4e6757457b0861a34564 [file] [log] [blame]
# Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file is organized as a two level map, where the outer key corresponds to
# the name of an analyzer error class (e.g. CompileTimeErrorCode), and the inner
# key corresponds to the name of a static variable in that class, describing a
# single diagnostic message. Ideally, each entry contains three parts:
#
# 1. A message template (problemMessage).
#
# 2. A suggestion for how to correct the problem (correctionMessage).
#
# 3. User-facing documentation for the problem (documentation).
#
# A message shouldn't indicate which kind of diagnostic it is, for example,
# warning or error. This is implied by the analyzer error class. For example,
# all entries in `StaticWarningCode` are warnings.
#
# See the file [lib/src/fasta/diagnostics.md] for more details on how to write
# good diagnostic messages.
#
# A message used for internal errors should have key that starts with
# "InternalProblem". This way, UX review can prioritize it accordingly.
#
# Eventually, we'd like to have all diagnostics in one shared location. However,
# for now, we have analyzer error codes and CFE error codes in separate files.
# See `pkg/front_end/messages.yaml` for the CFE error codes.
#
# ## Parameter Substitution in problemMessage and correctionMessage
#
# The fields `problemMessage` and `correctionMessage` are subject to parameter
# substitution. When the compiler reports a problem, it may also specify a list
# of values to be substituted into the message. Parameters are declared using
# placeholders of the form `{INTEGER}`, e.g. `{0}` is the zeroth parameter.
AnalysisOptionsErrorCode:
INCLUDED_FILE_PARSE_ERROR:
problemMessage: "{3} in {0}({1}..{2})"
hasPublishedDocs: false
comment: |-
An error code indicating that there is a syntactic error in the included
file.
Parameters:
0: the path of the file containing the error
1: the starting offset of the text in the file that contains the error
2: the ending offset of the text in the file that contains the error
3: the error message
PARSE_ERROR:
problemMessage: "{0}"
hasPublishedDocs: false
comment: |-
An error code indicating that there is a syntactic error in the file.
Parameters:
0: the error message from the parse error
AnalysisOptionsHintCode:
DEPRECATED_LINT:
problemMessage: "'{0}' is a deprecated lint rule and should not be used."
correctionMessage: Try removing '{0}'.
hasPublishedDocs: false
comment: |-
A hint code indicating reference to a deprecated lint.
Parameters:
0: the rule name
DEPRECATED_LINT_WITH_REPLACEMENT:
problemMessage: "'{0}' is deprecated and should be replaced by '{1}'."
correctionMessage: "Try replacing '{0}' with '{1}'."
hasPublishedDocs: false
comment: |-
A hint code indicating reference to a deprecated lint.
Parameters:
0: the deprecated lint name
1: the replacing rule name
DUPLICATE_RULE:
problemMessage: "The rule {0} is already specified and doesn't need to be specified again."
correctionMessage: "Try removing all but one specification of the rule."
hasPublishedDocs: false
comment: |-
Duplicate rules.
Parameters:
0: the rule name
AnalysisOptionsWarningCode:
ANALYSIS_OPTION_DEPRECATED:
problemMessage: "The option '{0}' is no longer supported."
hasPublishedDocs: false
comment: |
An error code indicating that the given option is deprecated.
Parameters:
0: the option name
ANALYSIS_OPTION_DEPRECATED_WITH_REPLACEMENT:
sharedName: ANALYSIS_OPTION_DEPRECATED
problemMessage: "The option '{0}' is no longer supported."
correctionMessage: "Try using the new '{1}' option."
hasPublishedDocs: false
comment: |-
An error code indicating that the given option is deprecated.
Parameters:
0: the option name
1: the replacement option name
INCLUDED_FILE_WARNING:
problemMessage: "Warning in the included options file {0}({1}..{2}): {3}"
hasPublishedDocs: false
comment: |-
An error code indicating a specified include file has a warning.
Parameters:
0: the path of the file containing the warnings
1: the starting offset of the text in the file that contains the warning
2: the ending offset of the text in the file that contains the warning
3: the warning message
INCLUDE_FILE_NOT_FOUND:
problemMessage: "The include file '{0}' in '{1}' can't be found when analyzing '{2}'."
hasPublishedDocs: false
comment: |-
An error code indicating a specified include file could not be found.
Parameters:
0: the URI of the file to be included
1: the path of the file containing the include directive
2: the path of the context being analyzed
INCOMPATIBLE_LINT:
problemMessage: "The rule '{0}' is incompatible with the rule '{1}'."
correctionMessage: "Try removing one of the incompatible rules."
hasPublishedDocs: false
comment: |-
An error code indicating an incompatible rule.
Parameters:
0: the rule name
1: the incompatible rule
INVALID_OPTION:
problemMessage: "Invalid option specified for '{0}': {1}"
hasPublishedDocs: false
comment: |-
An error code indicating that a plugin is being configured with an invalid
value for an option and a detail message is provided.
Parameters:
0: the option name
1: the detail message
INVALID_SECTION_FORMAT:
problemMessage: "Invalid format for the '{0}' section."
hasPublishedDocs: false
comment: |-
An error code indicating an invalid format for an options file section.
Parameters:
0: the section name
MULTIPLE_PLUGINS:
problemMessage: "Multiple plugins can't be enabled."
correctionMessage: "Remove all plugins following the first, '{0}'."
hasPublishedDocs: false
comment: |-
An error code indicating multiple plugins have been specified as enabled.
Parameters:
0: the name of the first plugin
RECURSIVE_INCLUDE_FILE:
problemMessage: "The include file '{0}' in '{1}' includes itself recursively."
correctionMessage: "Try changing the chain of 'include's to not re-include this file."
hasPublishedDocs: false
comment: |-
An error code indicating a specified include file includes itself recursively.
Parameters:
0: the URI of the file to be included
1: the path of the file containing the include directive
REMOVED_LINT:
problemMessage: "'{0}' was removed in Dart '{1}'"
correctionMessage: "Remove the reference to '{0}'."
hasPublishedDocs: false
comment: |-
An error code indicating a removed lint rule.
Parameters:
0: the rule name
1: the SDK version in which the lint was removed
REPLACED_LINT:
problemMessage: "'{0}' was replaced by '{2}' in Dart '{1}'."
correctionMessage: "Replace '{0}' with '{1}'."
hasPublishedDocs: false
comment: |-
An error code indicating a removed lint rule.
Parameters:
0: the rule name
1: the SDK version in which the lint was removed
2: the name of a replacing lint
UNDEFINED_LINT:
problemMessage: "'{0}' is not a recognized lint rule."
correctionMessage: "Try using the name of a recognized lint rule."
hasPublishedDocs: false
comment: |-
An error code indicating an undefined lint rule.
Parameters:
0: the rule name
UNRECOGNIZED_ERROR_CODE:
problemMessage: "'{0}' isn't a recognized error code."
hasPublishedDocs: false
comment: |-
An error code indicating that an unrecognized error code is being used to
specify an error filter.
Parameters:
0: the unrecognized error code
UNSUPPORTED_OPTION_WITHOUT_VALUES:
problemMessage: "The option '{1}' isn't supported by '{0}'."
hasPublishedDocs: false
comment: |-
An error code indicating that a plugin is being configured with an
unsupported option and legal options are provided.
Parameters:
0: the plugin name
1: the unsupported option key
UNSUPPORTED_OPTION_WITH_LEGAL_VALUE:
problemMessage: "The option '{1}' isn't supported by '{0}'. Try using the only supported option: '{2}'."
hasPublishedDocs: false
comment: |-
An error code indicating that a plugin is being configured with an
unsupported option where there is just one legal value.
Parameters:
0: the plugin name
1: the unsupported option key
2: the legal value
UNSUPPORTED_OPTION_WITH_LEGAL_VALUES:
problemMessage: "The option '{1}' isn't supported by '{0}'."
correctionMessage: "Try using one of the supported options: {2}."
hasPublishedDocs: false
comment: |-
An error code indicating that a plugin is being configured with an
unsupported option and legal options are provided.
Parameters:
0: the plugin name
1: the unsupported option key
2: legal values
UNSUPPORTED_VALUE:
problemMessage: "The value '{1}' isn't supported by '{0}'."
correctionMessage: "Try using one of the supported options: {2}."
hasPublishedDocs: false
comment: |-
An error code indicating that an option entry is being configured with an
unsupported value.
Parameters:
0: the option name
1: the unsupported value
2: legal values
CompileTimeErrorCode:
ABSTRACT_FIELD_CONSTRUCTOR_INITIALIZER:
sharedName: ABSTRACT_FIELD_INITIALIZER
problemMessage: "Abstract fields can't have initializers."
correctionMessage: "Try removing the field initializer or the 'abstract' keyword from the field declaration."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a field that has the `abstract`
modifier also has an initializer.
#### Examples
The following code produces this diagnostic because `f` is marked as
`abstract` and has an initializer:
```dart
abstract class C {
abstract int [!f!] = 0;
}
```
The following code produces this diagnostic because `f` is marked as
`abstract` and there's an initializer in the constructor:
```dart
abstract class C {
abstract int f;
C() : [!f!] = 0;
}
```
#### Common fixes
If the field must be abstract, then remove the initializer:
```dart
abstract class C {
abstract int f;
}
```
If the field isn't required to be abstract, then remove the keyword:
```dart
abstract class C {
int f = 0;
}
```
ABSTRACT_FIELD_INITIALIZER:
problemMessage: "Abstract fields can't have initializers."
correctionMessage: "Try removing the initializer or the 'abstract' keyword."
hasPublishedDocs: true
comment: No parameters.
ABSTRACT_SUPER_MEMBER_REFERENCE:
problemMessage: "The {0} '{1}' is always abstract in the supertype."
hasPublishedDocs: true
comment: |-
Parameters:
0: the display name for the kind of the found abstract member
1: the name of the member
documentation: |-
#### Description
The analyzer produces this diagnostic when an inherited member is
referenced using `super`, but there is no concrete implementation of the
member in the superclass chain. Abstract members can't be invoked.
#### Example
The following code produces this diagnostic because `B` doesn't inherit a
concrete implementation of `a`:
```dart
abstract class A {
int get a;
}
class B extends A {
int get a => super.[!a!];
}
```
#### Common fixes
Remove the invocation of the abstract member, possibly replacing it with an
invocation of a concrete member.
TODO(brianwilkerson): This either needs to be generalized (use 'member'
rather than '{0}') or split into multiple codes.
AMBIGUOUS_EXPORT:
problemMessage: "The name '{0}' is defined in the libraries '{1}' and '{2}'."
correctionMessage: Try removing the export of one of the libraries, or explicitly hiding the name in one of the export directives.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the ambiguous element
1: the name of the first library in which the type is found
2: the name of the second library in which the type is found
documentation: |-
#### Description
The analyzer produces this diagnostic when two or more export directives
cause the same name to be exported from multiple libraries.
#### Example
Given a file `a.dart` containing
```dart
%uri="lib/a.dart"
class C {}
```
And a file `b.dart` containing
```dart
%uri="lib/b.dart"
class C {}
```
The following code produces this diagnostic because the name `C` is being
exported from both `a.dart` and `b.dart`:
```dart
export 'a.dart';
export [!'b.dart'!];
```
#### Common fixes
If none of the names in one of the libraries needs to be exported, then
remove the unnecessary export directives:
```dart
export 'a.dart';
```
If all of the export directives are needed, then hide the name in all
except one of the directives:
```dart
export 'a.dart';
export 'b.dart' hide C;
```
AMBIGUOUS_EXTENSION_MEMBER_ACCESS:
problemMessage: "A member named '{0}' is defined in {1}, and none are more specific."
correctionMessage: Try using an extension override to specify the extension you want to be chosen.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the member
1: the names of the declaring extensions
documentation: |-
#### Description
When code refers to a member of an object (for example, `o.m()` or `o.m` or
`o[i]`) where the static type of `o` doesn't declare the member (`m` or
`[]`, for example), then the analyzer tries to find the member in an
extension. For example, if the member is `m`, then the analyzer looks for
extensions that declare a member named `m` and have an extended type that
the static type of `o` can be assigned to. When there's more than one such
extension in scope, the extension whose extended type is most specific is
selected.
The analyzer produces this diagnostic when none of the extensions has an
extended type that's more specific than the extended types of all of the
other extensions, making the reference to the member ambiguous.
#### Example
The following code produces this diagnostic because there's no way to
choose between the member in `E1` and the member in `E2`:
```dart
extension E1 on String {
int get charCount => 1;
}
extension E2 on String {
int get charCount => 2;
}
void f(String s) {
print(s.[!charCount!]);
}
```
#### Common fixes
If you don't need both extensions, then you can delete or hide one of them.
If you need both, then explicitly select the one you want to use by using
an extension override:
```dart
extension E1 on String {
int get charCount => length;
}
extension E2 on String {
int get charCount => length;
}
void f(String s) {
print(E2(s).charCount);
}
```
AMBIGUOUS_IMPORT:
problemMessage: "The name '{0}' is defined in the libraries {1}."
correctionMessage: "Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the ambiguous type
1: the names of the libraries that the type is found
documentation: |-
#### Description
The analyzer produces this diagnostic when a name is referenced that is
declared in two or more imported libraries.
#### Example
Given a library (`a.dart`) that defines a class (`C` in this example):
```dart
%uri="lib/a.dart"
class A {}
class C {}
```
And a library (`b.dart`) that defines a different class with the same name:
```dart
%uri="lib/b.dart"
class B {}
class C {}
```
The following code produces this diagnostic:
```dart
import 'a.dart';
import 'b.dart';
void f([!C!] c1, [!C!] c2) {}
```
#### Common fixes
If any of the libraries aren't needed, then remove the import directives
for them:
```dart
import 'a.dart';
void f(C c1, C c2) {}
```
If the name is still defined by more than one library, then add a `hide`
clause to the import directives for all except one library:
```dart
import 'a.dart' hide C;
import 'b.dart';
void f(C c1, C c2) {}
```
If you must be able to reference more than one of these types, then add a
prefix to each of the import directives, and qualify the references with
the appropriate prefix:
```dart
import 'a.dart' as a;
import 'b.dart' as b;
void f(a.C c1, b.C c2) {}
```
AMBIGUOUS_SET_OR_MAP_LITERAL_BOTH:
problemMessage: "The literal can't be either a map or a set because it contains at least one literal map entry or a spread operator spreading a 'Map', and at least one element which is neither of these."
correctionMessage: Try removing or changing some of the elements so that all of the elements are consistent.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
Because map and set literals use the same delimiters (`{` and `}`), the
analyzer looks at the type arguments and the elements to determine which
kind of literal you meant. When there are no type arguments, then the
analyzer uses the types of the elements. If all of the elements are literal
map entries and all of the spread operators are spreading a `Map` then it's
a `Map`. If none of the elements are literal map entries and all of the
spread operators are spreading an `Iterable`, then it's a `Set`. If neither
of those is true then it's ambiguous.
The analyzer produces this diagnostic when at least one element is a
literal map entry or a spread operator spreading a `Map`, and at least one
element is neither of these, making it impossible for the analyzer to
determine whether you are writing a map literal or a set literal.
#### Example
The following code produces this diagnostic:
```dart
union(Map<String, String> a, List<String> b, Map<String, String> c) =>
[!{...a, ...b, ...c}!];
```
The list `b` can only be spread into a set, and the maps `a` and `c` can
only be spread into a map, and the literal can't be both.
#### Common fixes
There are two common ways to fix this problem. The first is to remove all
of the spread elements of one kind or another, so that the elements are
consistent. In this case, that likely means removing the list and deciding
what to do about the now unused parameter:
```dart
union(Map<String, String> a, List<String> b, Map<String, String> c) =>
{...a, ...c};
```
The second fix is to change the elements of one kind into elements that are
consistent with the other elements. For example, you can add the elements
of the list as keys that map to themselves:
```dart
union(Map<String, String> a, List<String> b, Map<String, String> c) =>
{...a, for (String s in b) s: s, ...c};
```
AMBIGUOUS_SET_OR_MAP_LITERAL_EITHER:
problemMessage: "This literal must be either a map or a set, but the elements don't have enough information for type inference to work."
correctionMessage: Try adding type arguments to the literal (one for sets, two for maps).
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
Because map and set literals use the same delimiters (`{` and `}`), the
analyzer looks at the type arguments and the elements to determine which
kind of literal you meant. When there are no type arguments and all of the
elements are spread elements (which are allowed in both kinds of literals)
then the analyzer uses the types of the expressions that are being spread.
If all of the expressions have the type `Iterable`, then it's a set
literal; if they all have the type `Map`, then it's a map literal.
This diagnostic is produced when none of the expressions being spread have
a type that allows the analyzer to decide whether you were writing a map
literal or a set literal.
#### Example
The following code produces this diagnostic:
```dart
union(a, b) => [!{...a, ...b}!];
```
The problem occurs because there are no type arguments, and there is no
information about the type of either `a` or `b`.
#### Common fixes
There are three common ways to fix this problem. The first is to add type
arguments to the literal. For example, if the literal is intended to be a
map literal, you might write something like this:
```dart
union(a, b) => <String, String>{...a, ...b};
```
The second fix is to add type information so that the expressions have
either the type `Iterable` or the type `Map`. You can add an explicit cast
or, in this case, add types to the declarations of the two parameters:
```dart
union(List<int> a, List<int> b) => {...a, ...b};
```
The third fix is to add context information. In this case, that means
adding a return type to the function:
```dart
Set<String> union(a, b) => {...a, ...b};
```
In other cases, you might add a type somewhere else. For example, say the
original code looks like this:
```dart
union(a, b) {
var x = [!{...a, ...b}!];
return x;
}
```
You might add a type annotation on `x`, like this:
```dart
union(a, b) {
Map<String, String> x = {...a, ...b};
return x;
}
```
ARGUMENT_TYPE_NOT_ASSIGNABLE:
problemMessage: "The argument type '{0}' can't be assigned to the parameter type '{1}'. {2}"
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the actual argument type
1: the name of the expected type
2: additional information, if any, when problem is associated with records
documentation: |-
#### Description
The analyzer produces this diagnostic when the static type of an argument
can't be assigned to the static type of the corresponding parameter.
#### Example
The following code produces this diagnostic because a `num` can't be
assigned to a `String`:
```dart
String f(String x) => x;
String g(num y) => f([!y!]);
```
#### Common fixes
If possible, rewrite the code so that the static type is assignable. In the
example above you might be able to change the type of the parameter `y`:
```dart
String f(String x) => x;
String g(String y) => f(y);
```
If that fix isn't possible, then add code to handle the case where the
argument value isn't the required type. One approach is to coerce other
types to the required type:
```dart
String f(String x) => x;
String g(num y) => f(y.toString());
```
Another approach is to add explicit type tests and fallback code:
```dart
String f(String x) => x;
String g(Object y) => f(y is String ? y : '');
```
If you believe that the runtime type of the argument will always be the
same as the static type of the parameter, and you're willing to risk having
an exception thrown at runtime if you're wrong, then add an explicit cast:
```dart
String f(String x) => x;
String g(num y) => f(y as String);
```
ASSERT_IN_REDIRECTING_CONSTRUCTOR:
problemMessage: "A redirecting constructor can't have an 'assert' initializer."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a redirecting constructor (a
constructor that redirects to another constructor in the same class) has an
assert in the initializer list.
#### Example
The following code produces this diagnostic because the unnamed constructor
is a redirecting constructor and also has an assert in the initializer
list:
```dart
class C {
C(int x) : [!assert(x > 0)!], this.name();
C.name() {}
}
```
#### Common fixes
If the assert isn't needed, then remove it:
```dart
class C {
C(int x) : this.name();
C.name() {}
}
```
If the assert is needed, then convert the constructor into a factory
constructor:
```dart
class C {
factory C(int x) {
assert(x > 0);
return C.name();
}
C.name() {}
}
```
ASSIGNMENT_TO_CONST:
problemMessage: "Constant variables can't be assigned a value."
correctionMessage: "Try removing the assignment, or remove the modifier 'const' from the variable."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when it finds an assignment to a
top-level variable, a static field, or a local variable that has the
`const` modifier. The value of a compile-time constant can't be changed at
runtime.
#### Example
The following code produces this diagnostic because `c` is being assigned a
value even though it has the `const` modifier:
```dart
const c = 0;
void f() {
[!c!] = 1;
print(c);
}
```
#### Common fixes
If the variable must be assignable, then remove the `const` modifier:
```dart
var c = 0;
void f() {
c = 1;
print(c);
}
```
If the constant shouldn't be changed, then either remove the assignment or
use a local variable in place of references to the constant:
```dart
const c = 0;
void f() {
var v = 1;
print(v);
}
```
ASSIGNMENT_TO_FINAL:
problemMessage: "'{0}' can't be used as a setter because it's final."
correctionMessage: "Try finding a different setter, or making '{0}' non-final."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the final variable
documentation: |-
#### Description
The analyzer produces this diagnostic when it finds an invocation of a
setter, but there's no setter because the field with the same name was
declared to be `final` or `const`.
#### Example
The following code produces this diagnostic because `v` is final:
```dart
class C {
final v = 0;
}
f(C c) {
c.[!v!] = 1;
}
```
#### Common fixes
If you need to be able to set the value of the field, then remove the
modifier `final` from the field:
```dart
class C {
int v = 0;
}
f(C c) {
c.v = 1;
}
```
ASSIGNMENT_TO_FINAL_LOCAL:
problemMessage: "The final variable '{0}' can only be set once."
correctionMessage: "Try making '{0}' non-final."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the variable
documentation: |-
#### Description
The analyzer produces this diagnostic when a local variable that was
declared to be final is assigned after it was initialized.
#### Example
The following code produces this diagnostic because `x` is final, so it
can't have a value assigned to it after it was initialized:
```dart
void f() {
final x = 0;
[!x!] = 3;
print(x);
}
```
#### Common fixes
Remove the keyword `final`, and replace it with `var` if there's no type
annotation:
```dart
void f() {
var x = 0;
x = 3;
print(x);
}
```
ASSIGNMENT_TO_FINAL_NO_SETTER:
problemMessage: "There isn't a setter named '{0}' in class '{1}'."
correctionMessage: Try correcting the name to reference an existing setter, or declare the setter.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the reference
1: the name of the class
documentation: |-
#### Description
The analyzer produces this diagnostic when a reference to a setter is
found; there is no setter defined for the type; but there is a getter
defined with the same name.
#### Example
The following code produces this diagnostic because there is no setter
named `x` in `C`, but there is a getter named `x`:
```dart
class C {
int get x => 0;
set y(int p) {}
}
void f(C c) {
c.[!x!] = 1;
}
```
#### Common fixes
If you want to invoke an existing setter, then correct the name:
```dart
class C {
int get x => 0;
set y(int p) {}
}
void f(C c) {
c.y = 1;
}
```
If you want to invoke the setter but it just doesn't exist yet, then
declare it:
```dart
class C {
int get x => 0;
set x(int p) {}
set y(int p) {}
}
void f(C c) {
c.x = 1;
}
```
ASSIGNMENT_TO_FUNCTION:
problemMessage: "Functions can't be assigned a value."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the name of a function appears
on the left-hand side of an assignment expression.
#### Example
The following code produces this diagnostic because the assignment to the
function `f` is invalid:
```dart
void f() {}
void g() {
[!f!] = () {};
}
```
#### Common fixes
If the right-hand side should be assigned to something else, such as a
local variable, then change the left-hand side:
```dart
void f() {}
void g() {
var x = () {};
print(x);
}
```
If the intent is to change the implementation of the function, then define
a function-valued variable instead of a function:
```dart
void Function() f = () {};
void g() {
f = () {};
}
```
ASSIGNMENT_TO_METHOD:
problemMessage: "Methods can't be assigned a value."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the target of an assignment is a
method.
#### Example
The following code produces this diagnostic because `f` can't be assigned a
value because it's a method:
```dart
class C {
void f() {}
void g() {
[!f!] = null;
}
}
```
#### Common fixes
Rewrite the code so that there isn't an assignment to a method.
ASSIGNMENT_TO_TYPE:
problemMessage: "Types can't be assigned a value."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the name of a type name appears
on the left-hand side of an assignment expression.
#### Example
The following code produces this diagnostic because the assignment to the
class `C` is invalid:
```dart
class C {}
void f() {
[!C!] = null;
}
```
#### Common fixes
If the right-hand side should be assigned to something else, such as a
local variable, then change the left-hand side:
```dart
void f() {}
void g() {
var c = null;
print(c);
}
```
ASYNC_FOR_IN_WRONG_CONTEXT:
problemMessage: The async for-in loop can only be used in an async function.
correctionMessage: Try marking the function body with either 'async' or 'async*', or removing the 'await' before the for-in loop.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when an async for-in loop is found in
a function or method whose body isn't marked as being either `async` or
`async*`.
#### Example
The following code produces this diagnostic because the body of `f` isn't
marked as being either `async` or `async*`, but `f` contains an async
for-in loop:
```dart
void f(list) {
[!await!] for (var e in list) {
print(e);
}
}
```
#### Common fixes
If the function should return a `Future`, then mark the body with `async`:
```dart
Future<void> f(list) async {
await for (var e in list) {
print(e);
}
}
```
If the function should return a `Stream` of values, then mark the body with
`async*`:
```dart
Stream<void> f(list) async* {
await for (var e in list) {
print(e);
}
}
```
If the function should be synchronous, then remove the `await` before the
loop:
```dart
void f(list) {
for (var e in list) {
print(e);
}
}
```
AUGMENTATION_EXTENDS_CLAUSE_ALREADY_PRESENT:
problemMessage: The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause and it isn't allowed to be repeated or changed.
correctionMessage: Try removing the 'extends' clause, either here or in the augmentation target.
AUGMENTATION_MODIFIER_EXTRA:
problemMessage: The augmentation has the '{0}' modifier that the declaration doesn't have.
correctionMessage: Try removing the '{0}' modifier, or adding it to the declaration.
comment: |-
Parameters:
0: the lexeme of the modifier.
AUGMENTATION_MODIFIER_MISSING:
problemMessage: The augmentation is missing the '{0}' modifier that the declaration has.
correctionMessage: Try adding the '{0}' modifier, or removing it from the declaration.
comment: |-
Parameters:
0: the lexeme of the modifier.
AUGMENTATION_OF_DIFFERENT_DECLARATION_KIND:
problemMessage: Can't augment a {0} with a {1}.
correctionMessage: Try changing the augmentation to match the declaration kind.
hasPublishedDocs: false
comment: |-
Parameters:
0: the name of the declaration kind.
1: the name of the augmentation kind.
AUGMENTATION_TYPE_PARAMETER_BOUND:
problemMessage: The augmentation type parameter must have the same bound as the corresponding type parameter of the declaration.
correctionMessage: Try changing the augmentation to match the declaration type parameters.
hasPublishedDocs: false
AUGMENTATION_TYPE_PARAMETER_COUNT:
problemMessage: The augmentation must have the same number of type parameters as the declaration.
correctionMessage: Try changing the augmentation to match the declaration type parameters.
hasPublishedDocs: false
AUGMENTATION_TYPE_PARAMETER_NAME:
problemMessage: The augmentation type parameter must have the same name as the corresponding type parameter of the declaration.
correctionMessage: Try changing the augmentation to match the declaration type parameters.
hasPublishedDocs: false
AUGMENTATION_WITHOUT_DECLARATION:
problemMessage: The declaration being augmented doesn't exist.
correctionMessage: Try changing the augmentation to match an existing declaration.
hasPublishedDocs: false
AUGMENTATION_WITHOUT_IMPORT:
problemMessage: The library does not import this augmentation.
correctionMessage: Try updating the augmented library to import this augmentation.
hasPublishedDocs: false
AUGMENTATION_WITHOUT_LIBRARY:
problemMessage: The URI does not resolve to a library.
correctionMessage: Try updating the URI to reference the augmented library.
hasPublishedDocs: false
AUGMENTED_EXPRESSION_IS_NOT_SETTER:
problemMessage: The augmented declaration is not a setter, it can't be used to write a value.
correctionMessage: Try assigning a value to a setter.
hasPublishedDocs: false
AUGMENTED_EXPRESSION_IS_SETTER:
problemMessage: The augmented declaration is a setter, it can't be used to read a value.
correctionMessage: Try assigning a value to the augmented setter.
hasPublishedDocs: false
AUGMENTED_EXPRESSION_NOT_OPERATOR:
problemMessage: The enclosing augmentation doesn't augment the operator '{0}'.
correctionMessage: Try augmenting or invoking the correct operator.
hasPublishedDocs: false
comment: |-
Parameters:
0: the lexeme of the operator.
AWAIT_IN_LATE_LOCAL_VARIABLE_INITIALIZER:
problemMessage: "The 'await' expression can't be used in a 'late' local variable's initializer."
correctionMessage: "Try removing the 'late' modifier, or rewriting the initializer without using the 'await' expression."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a local variable that has the
`late` modifier uses an `await` expression in the initializer.
#### Example
The following code produces this diagnostic because an `await` expression
is used in the initializer for `v`, a local variable that is marked `late`:
```dart
Future<int> f() async {
late var v = [!await!] 42;
return v;
}
```
#### Common fixes
If the initializer can be rewritten to not use `await`, then rewrite it:
```dart
Future<int> f() async {
late var v = 42;
return v;
}
```
If the initializer can't be rewritten, then remove the `late` modifier:
```dart
Future<int> f() async {
var v = await 42;
return v;
}
```
AWAIT_IN_WRONG_CONTEXT:
problemMessage: The await expression can only be used in an async function.
correctionMessage: Try marking the function body with either 'async' or 'async*'.
hasPublishedDocs: false
comment: |-
16.30 Await Expressions: It is a compile-time error if the function
immediately enclosing _a_ is not declared asynchronous. (Where _a_ is the
await expression.)
AWAIT_OF_INCOMPATIBLE_TYPE:
problemMessage: "The 'await' expression can't be used for an expression with an extension type that is not a subtype of 'Future'."
correctionMessage: Try removing the `await`, or updating the extension type to implement 'Future'.
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when the type of the expression in
an `await` expression is an extension type, and the extension type isn't a
subclass of `Future`.
#### Example
The following code produces this diagnostic because the extension type `E`
isn't a subclass of `Future`:
```dart
extension type E(int i) {}
void f(E e) async {
[!await!] e;
}
```
#### Common fixes
If the extension type is correctly defined, then remove the `await`:
```dart
extension type E(int i) {}
void f(E e) {
e;
}
```
If the extension type is intended to be awaitable, then add `Future` (or a
subtype of `Future`) to the `implements` clause (adding an `implements`
clause if there isn't one already), and make the representation type
match:
```dart
extension type E(Future<int> i) implements Future<int> {}
void f(E e) async {
await e;
}
```
BASE_CLASS_IMPLEMENTED_OUTSIDE_OF_LIBRARY:
sharedName: INVALID_USE_OF_TYPE_OUTSIDE_LIBRARY
problemMessage: "The class '{0}' can't be implemented outside of its library because it's a base class."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the base class being implemented
documentation: |-
#### Description
The analyzer produces this diagnostic when an `extends`, `implements`,
`with`, or `on` clause uses a class or mixin in a way that isn't allowed
given the modifiers on that class or mixin's declaration.
The message specifies how the declaration is being used and why it isn't
allowed.
#### Example
Given a file `a.dart` that defines a base class `A`:
```dart
%uri="lib/a.dart"
base class A {}
```
The following code produces this diagnostic because the class `B`
implements the class `A`, but the `base` modifier prevents `A` from being
implemented outside of the library where it's defined:
```dart
import 'a.dart';
final class B implements [!A!] {}
```
#### Common fixes
Use of this type is restricted outside of its declaring library. If a
different, unrestricted type is available that can provide similar
functionality, then replace the type:
```dart
class B implements C {}
class C {}
```
If there isn't a different type that would be appropriate, then remove the
type, and possibly the whole clause:
```dart
class B {}
```
BASE_MIXIN_IMPLEMENTED_OUTSIDE_OF_LIBRARY:
sharedName: INVALID_USE_OF_TYPE_OUTSIDE_LIBRARY
problemMessage: "The mixin '{0}' can't be implemented outside of its library because it's a base mixin."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the base mixin being implemented
BODY_MIGHT_COMPLETE_NORMALLY:
problemMessage: The body might complete normally, causing 'null' to be returned, but the return type, '{0}', is a potentially non-nullable type.
correctionMessage: Try adding either a return or a throw statement at the end.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the return type
documentation: |-
#### Description
The analyzer produces this diagnostic when a method or function has a
return type that's [potentially non-nullable][] but would implicitly return
`null` if control reached the end of the function.
#### Examples
The following code produces this diagnostic because the method `m` has an
implicit return of `null` inserted at the end of the method, but the method
is declared to not return `null`:
```dart
class C {
int [!m!](int t) {
print(t);
}
}
```
The following code produces this diagnostic because the method `m` has an
implicit return of `null` inserted at the end of the method, but because
the class `C` can be instantiated with a non-nullable type argument, the
method is effectively declared to not return `null`:
```dart
class C<T> {
T [!m!](T t) {
print(t);
}
}
```
#### Common fixes
If there's a reasonable value that can be returned, then add a `return`
statement at the end of the method:
```dart
class C<T> {
T m(T t) {
print(t);
return t;
}
}
```
If the method won't reach the implicit return, then add a `throw` at the
end of the method:
```dart
class C<T> {
T m(T t) {
print(t);
throw '';
}
}
```
If the method intentionally returns `null` at the end, then add an
explicit return of `null` at the end of the method and change the
return type so that it's valid to return `null`:
```dart
class C<T> {
T? m(T t) {
print(t);
return null;
}
}
```
BREAK_LABEL_ON_SWITCH_MEMBER:
problemMessage: A break label resolves to the 'case' or 'default' statement.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a break in a case clause inside
a switch statement has a label that is associated with another case clause.
#### Example
The following code produces this diagnostic because the label `l` is
associated with the case clause for `0`:
```dart
%language=2.18
void f(int i) {
switch (i) {
l: case 0:
break;
case 1:
break [!l!];
}
}
```
#### Common fixes
If the intent is to transfer control to the statement after the switch,
then remove the label from the break statement:
```dart
void f(int i) {
switch (i) {
case 0:
break;
case 1:
break;
}
}
```
If the intent is to transfer control to a different case block, then use
`continue` rather than `break`:
```dart
%language=2.18
void f(int i) {
switch (i) {
l: case 0:
break;
case 1:
continue l;
}
}
```
BUILT_IN_IDENTIFIER_AS_TYPE:
problemMessage: The built-in identifier '{0}' can't be used as a type.
correctionMessage: Try correcting the name to match an existing type.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
documentation: |-
#### Description
The analyzer produces this diagnostic when a built-in identifier is used
where a type name is expected.
#### Example
The following code produces this diagnostic because `import` can't be used
as a type because it's a built-in identifier:
```dart
[!import!]<int> x;
```
#### Common fixes
Replace the built-in identifier with the name of a valid type:
```dart
List<int> x;
```
BUILT_IN_IDENTIFIER_AS_EXTENSION_NAME:
sharedName: BUILT_IN_IDENTIFIER_IN_DECLARATION
problemMessage: "The built-in identifier '{0}' can't be used as an extension name."
correctionMessage: Try choosing a different name for the extension.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
documentation: |-
#### Description
The analyzer produces this diagnostic when the name used in the declaration
of a class, extension, mixin, typedef, type parameter, or import prefix is
a built-in identifier. Built-in identifiers can't be used to name any of
these kinds of declarations.
#### Example
The following code produces this diagnostic because `mixin` is a built-in
identifier:
```dart
extension [!mixin!] on int {}
```
#### Common fixes
Choose a different name for the declaration.
BUILT_IN_IDENTIFIER_AS_EXTENSION_TYPE_NAME:
sharedName: BUILT_IN_IDENTIFIER_IN_DECLARATION
problemMessage: "The built-in identifier '{0}' can't be used as an extension type name."
correctionMessage: Try choosing a different name for the extension type.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
BUILT_IN_IDENTIFIER_AS_PREFIX_NAME:
sharedName: BUILT_IN_IDENTIFIER_IN_DECLARATION
problemMessage: "The built-in identifier '{0}' can't be used as a prefix name."
correctionMessage: Try choosing a different name for the prefix.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
BUILT_IN_IDENTIFIER_AS_TYPE_NAME:
sharedName: BUILT_IN_IDENTIFIER_IN_DECLARATION
problemMessage: "The built-in identifier '{0}' can't be used as a type name."
correctionMessage: Try choosing a different name for the type.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME:
sharedName: BUILT_IN_IDENTIFIER_IN_DECLARATION
problemMessage: "The built-in identifier '{0}' can't be used as a type parameter name."
correctionMessage: Try choosing a different name for the type parameter.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME:
sharedName: BUILT_IN_IDENTIFIER_IN_DECLARATION
problemMessage: "The built-in identifier '{0}' can't be used as a typedef name."
correctionMessage: Try choosing a different name for the typedef.
hasPublishedDocs: true
comment: |-
Parameters:
0: the built-in identifier that is being used
CASE_BLOCK_NOT_TERMINATED:
removedIn: "3.0"
problemMessage: "The last statement of the 'case' should be 'break', 'continue', 'rethrow', 'return', or 'throw'."
correctionMessage: Try adding one of the required statements.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the last statement in a `case`
block isn't one of the required terminators: `break`, `continue`,
`rethrow`, `return`, or `throw`.
#### Example
The following code produces this diagnostic because the `case` block ends
with an assignment:
```dart
%language=2.9
void f(int x) {
switch (x) {
[!case!] 0:
x += 2;
default:
x += 1;
}
}
```
#### Common fixes
Add one of the required terminators:
```dart
%language=2.9
void f(int x) {
switch (x) {
case 0:
x += 2;
break;
default:
x += 1;
}
}
```
CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS:
problemMessage: "The switch case expression type '{0}' can't override the '==' operator."
hasPublishedDocs: true
comment: |-
Parameters:
0: the this of the switch case expression
documentation: |-
#### Description
The analyzer produces this diagnostic when the type of the expression
following the keyword `case` has an implementation of the `==` operator
other than the one in `Object`.
#### Example
The following code produces this diagnostic because the expression
following the keyword `case` (`C(0)`) has the type `C`, and the class `C`
overrides the `==` operator:
```dart
%language=2.18
class C {
final int value;
const C(this.value);
bool operator ==(Object other) {
return false;
}
}
void f(C c) {
switch (c) {
case [!C(0)!]:
break;
}
}
```
#### Common fixes
If there isn't a strong reason not to do so, then rewrite the code to use
an if-else structure:
```dart
class C {
final int value;
const C(this.value);
bool operator ==(Object other) {
return false;
}
}
void f(C c) {
if (c == C(0)) {
// ...
}
}
```
If you can't rewrite the switch statement and the implementation of `==`
isn't necessary, then remove it:
```dart
%language=2.18
class C {
final int value;
const C(this.value);
}
void f(C c) {
switch (c) {
case C(0):
break;
}
}
```
If you can't rewrite the switch statement and you can't remove the
definition of `==`, then find some other value that can be used to control
the switch:
```dart
class C {
final int value;
const C(this.value);
bool operator ==(Object other) {
return false;
}
}
void f(C c) {
switch (c.value) {
case 0:
break;
}
}
```
CASE_EXPRESSION_TYPE_IS_NOT_SWITCH_EXPRESSION_SUBTYPE:
problemMessage: "The switch case expression type '{0}' must be a subtype of the switch expression type '{1}'."
hasPublishedDocs: true
comment: |-
Parameters:
0: the type of the case expression
1: the type of the switch expression
documentation: |-
#### Description
The analyzer produces this diagnostic when the expression following `case`
in a `switch` statement has a static type that isn't a subtype of the
static type of the expression following `switch`.
#### Example
The following code produces this diagnostic because `1` is an `int`, which
isn't a subtype of `String` (the type of `s`):
```dart
%language=2.18
void f(String s) {
switch (s) {
case [!1!]:
break;
}
}
```
#### Common fixes
If the value of the `case` expression is wrong, then change the `case`
expression so that it has the required type:
```dart
void f(String s) {
switch (s) {
case '1':
break;
}
}
```
If the value of the `case` expression is correct, then change the `switch`
expression to have the required type:
```dart
void f(int s) {
switch (s) {
case 1:
break;
}
}
```
CAST_TO_NON_TYPE:
problemMessage: "The name '{0}' isn't a type, so it can't be used in an 'as' expression."
correctionMessage: "Try changing the name to the name of an existing type, or creating a type with the name '{0}'."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type
documentation: |-
#### Description
The analyzer produces this diagnostic when the name following the `as` in a
cast expression is defined to be something other than a type.
#### Example
The following code produces this diagnostic because `x` is a variable, not
a type:
```dart
num x = 0;
int y = x as [!x!];
```
#### Common fixes
Replace the name with the name of a type:
```dart
num x = 0;
int y = x as int;
```
CLASS_USED_AS_MIXIN:
problemMessage: "The class '{0}' can't be used as a mixin because it's neither a mixin class nor a mixin."
comment: |-
Parameters:
0: the name of the class being used as a mixin
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a class that is neither a
`mixin class` nor a `mixin` is used in a `with` clause.
#### Example
The following code produces this diagnostic because the class `M` is being
used as a mixin, but it isn't defined as a `mixin class`:
```dart
class M {}
class C with [!M!] {}
```
#### Common fixes
If the class can be a pure mixin, then change `class` to `mixin`:
```dart
mixin M {}
class C with M {}
```
If the class needs to be both a class and a mixin, then add `mixin`:
```dart
mixin class M {}
class C with M {}
```
CLASS_INSTANTIATION_ACCESS_TO_INSTANCE_MEMBER:
sharedName: CLASS_INSTANTIATION_ACCESS_TO_MEMBER
problemMessage: "The instance member '{0}' can't be accessed on a class instantiation."
correctionMessage: Try changing the member name to the name of a constructor.
hasPublishedDocs: false
comment: |-
Parameters:
0: the name of the member
CLASS_INSTANTIATION_ACCESS_TO_UNKNOWN_MEMBER:
sharedName: CLASS_INSTANTIATION_ACCESS_TO_MEMBER
problemMessage: "The class '{0}' doesn't have a constructor named '{1}'."
correctionMessage: "Try invoking a different constructor, or defining a constructor named '{1}'."
hasPublishedDocs: false
comment: |-
Parameters:
0: the name of the class
1: the name of the member
CLASS_INSTANTIATION_ACCESS_TO_STATIC_MEMBER:
sharedName: CLASS_INSTANTIATION_ACCESS_TO_MEMBER
problemMessage: "The static member '{0}' can't be accessed on a class instantiation."
correctionMessage: Try removing the type arguments from the class name, or changing the member name to the name of a constructor.
hasPublishedDocs: false
comment: |-
Parameters:
0: the name of the member
NON_CONST_GENERATIVE_ENUM_CONSTRUCTOR:
problemMessage: Generative enum constructors must be 'const'.
correctionMessage: Try adding the keyword 'const'.
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when an enum declaration contains a
generative constructor that isn't marked as `const`.
#### Example
The following code produces this diagnostic because the constructor in `E`
isn't marked as being `const`:
```dart
enum E {
e;
[!E!]();
}
```
#### Common fixes
Add the `const` keyword before the constructor:
```dart
enum E {
e;
const E();
}
```
NON_CONSTANT_LIST_ELEMENT_FROM_DEFERRED_LIBRARY:
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
problemMessage: "Constant values from a deferred library can't be used as values in a 'const' list literal."
correctionMessage: "Try removing the keyword 'const' from the list literal or removing the keyword 'deferred' from the import."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a collection literal that is
either explicitly (because it's prefixed by the `const` keyword) or
implicitly (because it appears in a [constant context][]) a constant
contains a value that is declared in a library that is imported using a
deferred import. Constants are evaluated at compile time, and values from
deferred libraries aren't available at compile time.
For more information, check out
[Lazily loading a library](https://dart.dev/language/libraries#lazily-loading-a-library).
#### Example
Given a file `a.dart` that defines the constant `zero`:
```dart
%uri="lib/a.dart"
const zero = 0;
```
The following code produces this diagnostic because the constant list
literal contains `a.zero`, which is imported using a `deferred` import:
```dart
import 'a.dart' deferred as a;
var l = const [a.[!zero!]];
```
#### Common fixes
If the collection literal isn't required to be constant, then remove the
`const` keyword:
```dart
import 'a.dart' deferred as a;
var l = [a.zero];
```
If the collection is required to be constant and the imported constant must
be referenced, then remove the keyword `deferred` from the import:
```dart
import 'a.dart' as a;
var l = const [a.zero];
```
If you don't need to reference the constant, then replace it with a
suitable value:
```dart
var l = const [0];
```
NON_CONSTANT_MAP_KEY_FROM_DEFERRED_LIBRARY:
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
problemMessage: "Constant values from a deferred library can't be used as keys in a 'const' map literal."
correctionMessage: "Try removing the keyword 'const' from the map literal or removing the keyword 'deferred' from the import."
hasPublishedDocs: true
comment: No parameters.
NON_CONSTANT_MAP_VALUE_FROM_DEFERRED_LIBRARY:
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
problemMessage: "Constant values from a deferred library can't be used as values in a 'const' map literal."
correctionMessage: "Try removing the keyword 'const' from the map literal or removing the keyword 'deferred' from the import."
hasPublishedDocs: true
comment: No parameters.
NON_CONSTANT_RECORD_FIELD_FROM_DEFERRED_LIBRARY:
problemMessage: "Constant values from a deferred library can't be used as fields in a 'const' record literal."
correctionMessage: "Try removing the keyword 'const' from the record literal or removing the keyword 'deferred' from the import."
hasPublishedDocs: false
comment: No parameters.
PATTERN_CONSTANT_FROM_DEFERRED_LIBRARY:
problemMessage: Constant values from a deferred library can't be used in patterns.
correctionMessage: Try removing the keyword 'deferred' from the import.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a pattern contains a value
declared in a different library, and that library is imported using a
deferred import. Constants are evaluated at compile time, but values from
deferred libraries aren't available at compile time.
For more information, check out
[Lazily loading a library](https://dart.dev/language/libraries#lazily-loading-a-library).
#### Example
Given a file `a.dart` that defines the constant `zero`:
```dart
%uri="lib/a.dart"
const zero = 0;
```
The following code produces this diagnostic because the constant pattern
`a.zero` is imported using a deferred import:
```dart
import 'a.dart' deferred as a;
void f(int x) {
switch (x) {
case a.[!zero!]:
// ...
break;
}
}
```
#### Common fixes
If you need to reference the constant from the imported library, then
remove the `deferred` keyword:
```dart
import 'a.dart' as a;
void f(int x) {
switch (x) {
case a.zero:
// ...
break;
}
}
```
If you need to reference the constant from the imported library and also
need the imported library to be deferred, then rewrite the switch
statement as a sequence of `if` statements:
```dart
import 'a.dart' deferred as a;
void f(int x) {
if (x == a.zero) {
// ...
}
}
```
If you don't need to reference the constant, then replace the case
expression:
```dart
void f(int x) {
switch (x) {
case 0:
// ...
break;
}
}
```
RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA:
problemMessage: "A record literal with exactly one positional field requires a trailing comma."
correctionMessage: Try adding a trailing comma.
hasPublishedDocs: true
SET_ELEMENT_FROM_DEFERRED_LIBRARY:
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
problemMessage: "Constant values from a deferred library can't be used as values in a 'const' set literal."
correctionMessage: "Try removing the keyword 'const' from the set literal or removing the keyword 'deferred' from the import."
hasPublishedDocs: true
comment: No parameters.
CONCRETE_CLASS_HAS_ENUM_SUPERINTERFACE:
problemMessage: "Concrete classes can't have 'Enum' as a superinterface."
correctionMessage: Try specifying a different interface, or remove it from the list.
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a concrete class indirectly has
the class `Enum` as a superinterface.
#### Example
The following code produces this diagnostic because the concrete class `B`
has `Enum` as a superinterface as a result of implementing `A`:
```dart
abstract class A implements Enum {}
class [!B!] implements A {}
```
#### Common fixes
If the implemented class isn't the class you intend to implement, then
change it:
```dart
abstract class A implements Enum {}
class B implements C {}
class C {}
```
If the implemented class can be changed to not implement `Enum`, then do
so:
```dart
abstract class A {}
class B implements A {}
```
If the implemented class can't be changed to not implement `Enum`, then
remove it from the `implements` clause:
```dart
abstract class A implements Enum {}
class B {}
```
CONCRETE_CLASS_WITH_ABSTRACT_MEMBER:
problemMessage: "'{0}' must have a method body because '{1}' isn't abstract."
correctionMessage: "Try making '{1}' abstract, or adding a body to '{0}'."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the abstract method
1: the name of the enclosing class
documentation: |-
#### Description
The analyzer produces this diagnostic when a member of a concrete class is
found that doesn't have a concrete implementation. Concrete classes aren't
allowed to contain abstract members.
#### Example
The following code produces this diagnostic because `m` is an abstract
method but `C` isn't an abstract class:
```dart
class C {
[!void m();!]
}
```
#### Common fixes
If it's valid to create instances of the class, provide an implementation
for the member:
```dart
class C {
void m() {}
}
```
If it isn't valid to create instances of the class, mark the class as being
abstract:
```dart
abstract class C {
void m();
}
```
CONFLICTING_CONSTRUCTOR_AND_STATIC_FIELD:
sharedName: CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
problemMessage: "'{0}' can't be used to name both a constructor and a static field in this class."
correctionMessage: Try renaming either the constructor or the field.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the constructor and field
documentation: |-
#### Description
The analyzer produces this diagnostic when a named constructor and either a
static method or static field have the same name. Both are accessed using
the name of the class, so having the same name makes the reference
ambiguous.
#### Examples
The following code produces this diagnostic because the static field `foo`
and the named constructor `foo` have the same name:
```dart
class C {
C.[!foo!]();
static int foo = 0;
}
```
The following code produces this diagnostic because the static method `foo`
and the named constructor `foo` have the same name:
```dart
class C {
C.[!foo!]();
static void foo() {}
}
```
#### Common fixes
Rename either the member or the constructor.
CONFLICTING_CONSTRUCTOR_AND_STATIC_GETTER:
sharedName: CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
problemMessage: "'{0}' can't be used to name both a constructor and a static getter in this class."
correctionMessage: Try renaming either the constructor or the getter.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the constructor and getter
CONFLICTING_CONSTRUCTOR_AND_STATIC_METHOD:
sharedName: CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
problemMessage: "'{0}' can't be used to name both a constructor and a static method in this class."
correctionMessage: Try renaming either the constructor or the method.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the constructor
CONFLICTING_CONSTRUCTOR_AND_STATIC_SETTER:
sharedName: CONFLICTING_CONSTRUCTOR_AND_STATIC_MEMBER
problemMessage: "'{0}' can't be used to name both a constructor and a static setter in this class."
correctionMessage: Try renaming either the constructor or the setter.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the constructor and setter
CONFLICTING_FIELD_AND_METHOD:
problemMessage: "Class '{0}' can't define field '{1}' and have method '{2}.{1}' with the same name."
correctionMessage: "Try converting the getter to a method, or renaming the field to a name that doesn't conflict."
hasPublishedDocs: false
comment: |-
10.11 Class Member Conflicts: Let `C` be a class. It is a compile-time
error if `C` declares a getter or a setter with basename `n`, and has a
method named `n`.
Parameters:
0: the name of the class defining the conflicting field
1: the name of the conflicting field
2: the name of the class defining the method with which the field conflicts
CONFLICTING_GENERIC_INTERFACES:
problemMessage: "The {0} '{1}' can't implement both '{2}' and '{3}' because the type arguments are different."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the kind of the element implementing the conflicting interface
1: the name of the element implementing the conflicting interface
2: the first conflicting type
3: the second conflicting type
documentation: |-
#### Description
The analyzer produces this diagnostic when a class attempts to implement a
generic interface multiple times, and the values of the type arguments
aren't the same.
#### Example
The following code produces this diagnostic because `C` is defined to
implement both `I<int>` (because it extends `A`) and `I<String>` (because
it implements`B`), but `int` and `String` aren't the same type:
```dart
class I<T> {}
class A implements I<int> {}
class B implements I<String> {}
class [!C!] extends A implements B {}
```
#### Common fixes
Rework the type hierarchy to avoid this situation. For example, you might
make one or both of the inherited types generic so that `C` can specify the
same type for both type arguments:
```dart
class I<T> {}
class A<S> implements I<S> {}
class B implements I<String> {}
class C extends A<String> implements B {}
```
CONFLICTING_INHERITED_METHOD_AND_SETTER:
problemMessage: "The {0} '{1}' can't inherit both a method and a setter named '{2}'."
hasPublishedDocs: false
comment: |-
10.11 Class Member Conflicts: Let `C` be a class. It is a compile-time
error if the interface of `C` has an instance method named `n` and an
instance setter with basename `n`.
Parameters:
0: the name of the enclosing element kind - class, extension type, etc
1: the name of the enclosing element
2: the name of the conflicting method / setter
CONFLICTING_METHOD_AND_FIELD:
problemMessage: "Class '{0}' can't define method '{1}' and have field '{2}.{1}' with the same name."
correctionMessage: "Try converting the method to a getter, or renaming the method to a name that doesn't conflict."
hasPublishedDocs: false
comment: |-
10.11 Class Member Conflicts: Let `C` be a class. It is a compile-time
error if `C` declares a method named `n`, and has a getter or a setter
with basename `n`.
Parameters:
0: the name of the class defining the conflicting method
1: the name of the conflicting method
2: the name of the class defining the field with which the method conflicts
CONFLICTING_STATIC_AND_INSTANCE:
problemMessage: "Class '{0}' can't define static member '{1}' and have instance member '{2}.{1}' with the same name."
correctionMessage: "Try renaming the member to a name that doesn't conflict."
hasPublishedDocs: false
comment: |-
10.11 Class Member Conflicts: Let `C` be a class. It is a compile-time
error if `C` declares a static member with basename `n`, and has an
instance member with basename `n`.
Parameters:
0: the name of the class defining the conflicting member
1: the name of the conflicting static member
2: the name of the class defining the field with which the method conflicts
CONFLICTING_TYPE_VARIABLE_AND_CLASS:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_CONTAINER
problemMessage: "'{0}' can't be used to name both a type variable and the class in which the type variable is defined."
correctionMessage: Try renaming either the type variable or the class.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
documentation: |-
#### Description
The analyzer produces this diagnostic when a class, mixin, or extension
declaration declares a type parameter with the same name as the class,
mixin, or extension that declares it.
#### Example
The following code produces this diagnostic because the type parameter `C`
has the same name as the class `C` of which it's a part:
```dart
class C<[!C!]> {}
```
#### Common fixes
Rename either the type parameter, or the class, mixin, or extension:
```dart
class C<T> {}
```
CONFLICTING_TYPE_VARIABLE_AND_ENUM:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_CONTAINER
problemMessage: "'{0}' can't be used to name both a type variable and the enum in which the type variable is defined."
correctionMessage: Try renaming either the type variable or the enum.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_EXTENSION:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_CONTAINER
problemMessage: "'{0}' can't be used to name both a type variable and the extension in which the type variable is defined."
correctionMessage: Try renaming either the type variable or the extension.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_EXTENSION_TYPE:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_CONTAINER
problemMessage: "'{0}' can't be used to name both a type variable and the extension type in which the type variable is defined."
correctionMessage: Try renaming either the type variable or the extension.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_MIXIN:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_CONTAINER
problemMessage: "'{0}' can't be used to name both a type variable and the mixin in which the type variable is defined."
correctionMessage: Try renaming either the type variable or the mixin.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_MEMBER_CLASS:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_MEMBER
problemMessage: "'{0}' can't be used to name both a type variable and a member in this class."
correctionMessage: Try renaming either the type variable or the member.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
documentation: |-
#### Description
The analyzer produces this diagnostic when a class, mixin, or extension
declaration declares a type parameter with the same name as one of the
members of the class, mixin, or extension that declares it.
#### Example
The following code produces this diagnostic because the type parameter `T`
has the same name as the field `T`:
```dart
class C<[!T!]> {
int T = 0;
}
```
#### Common fixes
Rename either the type parameter or the member with which it conflicts:
```dart
class C<T> {
int total = 0;
}
```
CONFLICTING_TYPE_VARIABLE_AND_MEMBER_MIXIN:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_MEMBER
problemMessage: "'{0}' can't be used to name both a type variable and a member in this mixin."
correctionMessage: Try renaming either the type variable or the member.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_MEMBER_ENUM:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_MEMBER
problemMessage: "'{0}' can't be used to name both a type variable and a member in this enum."
correctionMessage: Try renaming either the type variable or the member.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_MEMBER_EXTENSION:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_MEMBER
problemMessage: "'{0}' can't be used to name both a type variable and a member in this extension."
correctionMessage: Try renaming either the type variable or the member.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONFLICTING_TYPE_VARIABLE_AND_MEMBER_EXTENSION_TYPE:
sharedName: CONFLICTING_TYPE_VARIABLE_AND_MEMBER
problemMessage: "'{0}' can't be used to name both a type variable and a member in this extension type."
correctionMessage: Try renaming either the type variable or the member.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the type variable
CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH:
problemMessage: "In a const constructor, a value of type '{0}' can't be assigned to the field '{1}', which has type '{2}'."
correctionMessage: "Try using a subtype, or removing the keyword 'const'."
hasPublishedDocs: false
comment: |-
16.12.2 Const: It is a compile-time error if evaluation of a constant
object results in an uncaught exception being thrown.
Parameters:
0: the type of the runtime value of the argument
1: the name of the field
2: the type of the field
CONST_CONSTRUCTOR_CONSTANT_FROM_DEFERRED_LIBRARY:
sharedName: COLLECTION_ELEMENT_FROM_DEFERRED_LIBRARY
problemMessage: "Constant values from a deferred library can't be used as values in a 'const' constructor."
correctionMessage: "Try removing the keyword 'const' from the constructor or removing the keyword 'deferred' from the import."
hasPublishedDocs: true
comment: No parameters.
CONST_CONSTRUCTOR_PARAM_TYPE_MISMATCH:
problemMessage: "A value of type '{0}' can't be assigned to a parameter of type '{1}' in a const constructor."
correctionMessage: "Try using a subtype, or removing the keyword 'const'."
hasPublishedDocs: true
comment: |-
Parameters:
0: the type of the runtime value of the argument
1: the static type of the parameter
documentation: |-
#### Description
The analyzer produces this diagnostic when the runtime type of a constant
value can't be assigned to the static type of a constant constructor's
parameter.
#### Example
The following code produces this diagnostic because the runtime type of `i`
is `int`, which can't be assigned to the static type of `s`:
```dart
class C {
final String s;
const C(this.s);
}
const dynamic i = 0;
void f() {
const C([!i!]);
}
```
#### Common fixes
Pass a value of the correct type to the constructor:
```dart
class C {
final String s;
const C(this.s);
}
const dynamic i = 0;
void f() {
const C('$i');
}
```
CONST_CONSTRUCTOR_THROWS_EXCEPTION:
problemMessage: "Const constructors can't throw exceptions."
correctionMessage: "Try removing the throw statement, or removing the keyword 'const'."
hasPublishedDocs: false
comment: |-
16.12.2 Const: It is a compile-time error if evaluation of a constant
object results in an uncaught exception being thrown.
CONST_CONSTRUCTOR_WITH_FIELD_INITIALIZED_BY_NON_CONST:
problemMessage: "Can't define the 'const' constructor because the field '{0}' is initialized with a non-constant value."
correctionMessage: "Try initializing the field to a constant value, or removing the keyword 'const' from the constructor."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the field
documentation: |-
#### Description
The analyzer produces this diagnostic when a constructor has the keyword
`const`, but a field in the class is initialized to a non-constant value.
#### Example
The following code produces this diagnostic because the field `s` is
initialized to a non-constant value:
```dart
String x = '3';
class C {
final String s = x;
[!const!] C();
}
```
#### Common fixes
If the field can be initialized to a constant value, then change the
initializer to a constant expression:
```dart
class C {
final String s = '3';
const C();
}
```
If the field can't be initialized to a constant value, then remove the
keyword `const` from the constructor:
```dart
String x = '3';
class C {
final String s = x;
C();
}
```
CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELD:
problemMessage: "This constructor can't be declared 'const' because a mixin adds the instance field: {0}."
correctionMessage: "Try removing the 'const' keyword or removing the 'with' clause from the class declaration, or removing the field from the mixin class."
hasPublishedDocs: false
comment: |-
7.6.3 Constant Constructors: The superinitializer that appears, explicitly
or implicitly, in the initializer list of a constant constructor must
specify a constant constructor of the superclass of the immediately
enclosing class or a compile-time error occurs.
12.1 Mixin Application: For each generative constructor named ... an
implicitly declared constructor named ... is declared. If Sq is a
generative const constructor, and M does not declare any fields, Cq is
also a const constructor.
Parameters:
0: the name of the instance field.
CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELDS:
sharedName: CONST_CONSTRUCTOR_WITH_MIXIN_WITH_FIELD
problemMessage: "This constructor can't be declared 'const' because the mixins add the instance fields: {0}."
correctionMessage: "Try removing the 'const' keyword or removing the 'with' clause from the class declaration, or removing the fields from the mixin classes."
hasPublishedDocs: false
comment: |-
7.6.3 Constant Constructors: The superinitializer that appears, explicitly
or implicitly, in the initializer list of a constant constructor must
specify a constant constructor of the superclass of the immediately
enclosing class or a compile-time error occurs.
12.1 Mixin Application: For each generative constructor named ... an
implicitly declared constructor named ... is declared. If Sq is a
generative const constructor, and M does not declare any fields, Cq is
also a const constructor.
Parameters:
0: the names of the instance fields.
CONST_CONSTRUCTOR_WITH_NON_CONST_SUPER:
problemMessage: "A constant constructor can't call a non-constant super constructor of '{0}'."
correctionMessage: "Try calling a constant constructor in the superclass, or removing the keyword 'const' from the constructor."
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the superclass
documentation: |-
#### Description
The analyzer produces this diagnostic when a constructor that is marked as
`const` invokes a constructor from its superclass that isn't marked as
`const`.
#### Example
The following code produces this diagnostic because the `const` constructor
in `B` invokes the constructor `nonConst` from the class `A`, and the
superclass constructor isn't a `const` constructor:
```dart
class A {
const A();
A.nonConst();
}
class B extends A {
const B() : [!super.nonConst()!];
}
```
#### Common fixes
If it isn't essential to invoke the superclass constructor that is
currently being invoked, then invoke a constant constructor from the
superclass:
```dart
class A {
const A();
A.nonConst();
}
class B extends A {
const B() : super();
}
```
If it's essential that the current constructor be invoked and if you can
modify it, then add `const` to the constructor in the superclass:
```dart
class A {
const A();
const A.nonConst();
}
class B extends A {
const B() : super.nonConst();
}
```
If it's essential that the current constructor be invoked and you can't
modify it, then remove `const` from the constructor in the subclass:
```dart
class A {
const A();
A.nonConst();
}
class B extends A {
B() : super.nonConst();
}
```
CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD:
problemMessage: "Can't define a const constructor for a class with non-final fields."
correctionMessage: "Try making all of the fields final, or removing the keyword 'const' from the constructor."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a constructor is marked as a
const constructor, but the constructor is defined in a class that has at
least one non-final instance field (either directly or by inheritance).
#### Example
The following code produces this diagnostic because the field `x` isn't
final:
```dart
class C {
int x;
const [!C!](this.x);
}
```
#### Common fixes
If it's possible to mark all of the fields as final, then do so:
```dart
class C {
final int x;
const C(this.x);
}
```
If it isn't possible to mark all of the fields as final, then remove the
keyword `const` from the constructor:
```dart
class C {
int x;
C(this.x);
}
```
CONST_DEFERRED_CLASS:
problemMessage: "Deferred classes can't be created with 'const'."
correctionMessage: "Try using 'new' to create the instance, or changing the import to not be deferred."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a class from a library that is
imported using a deferred import is used to create a `const` object.
Constants are evaluated at compile time, and classes from deferred
libraries aren't available at compile time.
For more information, check out
[Lazily loading a library](https://dart.dev/language/libraries#lazily-loading-a-library).
#### Example
The following code produces this diagnostic because it attempts to create a
`const` instance of a class from a deferred library:
```dart
import 'dart:convert' deferred as convert;
const json2 = [!convert.JsonCodec()!];
```
#### Common fixes
If the object isn't required to be a constant, then change the code so that
a non-constant instance is created:
```dart
import 'dart:convert' deferred as convert;
final json2 = convert.JsonCodec();
```
If the object must be a constant, then remove `deferred` from the import
directive:
```dart
import 'dart:convert' as convert;
const json2 = convert.JsonCodec();
```
CONST_EVAL_ASSERTION_FAILURE:
problemMessage: "The assertion in this constant expression failed."
hasPublishedDocs: false
CONST_EVAL_ASSERTION_FAILURE_WITH_MESSAGE:
problemMessage: "An assertion failed with message '{0}'."
hasPublishedDocs: false
comment: |-
Parameters:
0: the message of the assertion
CONST_EVAL_EXTENSION_METHOD:
problemMessage: "Extension methods can't be used in constant expressions."
hasPublishedDocs: false
CONST_EVAL_EXTENSION_TYPE_METHOD:
problemMessage: "Extension type methods can't be used in constant expressions."
hasPublishedDocs: false
CONST_EVAL_FOR_ELEMENT:
problemMessage: "Constant expressions don't support 'for' elements."
correctionMessage: "Try replacing the 'for' element with a spread, or removing 'const'."
hasPublishedDocs: false
CONST_EVAL_PROPERTY_ACCESS:
problemMessage: "The property '{0}' can't be accessed on the type '{1}' in a constant expression."
hasPublishedDocs: false
comment: |-
Parameters:
0: the name of the property being accessed
1: the type with the property being accessed
CONST_EVAL_METHOD_INVOCATION:
problemMessage: "Methods can't be invoked in constant expressions."
hasPublishedDocs: false
CONST_EVAL_THROWS_EXCEPTION:
problemMessage: Evaluation of this constant expression throws an exception.
hasPublishedDocs: false
comment: |-
16.12.2 Const: It is a compile-time error if evaluation of a constant
object results in an uncaught exception being thrown.
CONST_EVAL_THROWS_IDBZE:
problemMessage: Evaluation of this constant expression throws an IntegerDivisionByZeroException.
hasPublishedDocs: false
comment: |-
16.12.2 Const: It is a compile-time error if evaluation of a constant
object results in an uncaught exception being thrown.
CONST_EVAL_TYPE_BOOL:
problemMessage: "In constant expressions, operands of this operator must be of type 'bool'."
hasPublishedDocs: false
comment: |-
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
for text about "An expression of the form !e1", "An expression of the form
e1 && e2", and "An expression of the form e1 || e2".
CONST_EVAL_TYPE_BOOL_INT:
problemMessage: "In constant expressions, operands of this operator must be of type 'bool' or 'int'."
hasPublishedDocs: false
comment: |-
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
for text about "An expression of the form e1 & e2".
CONST_EVAL_TYPE_BOOL_NUM_STRING:
problemMessage: "In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null'."
hasPublishedDocs: false
comment: |-
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
for text about "A literal string".
CONST_EVAL_TYPE_INT:
problemMessage: "In constant expressions, operands of this operator must be of type 'int'."
hasPublishedDocs: false
comment: |-
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
for text about "An expression of the form ~e1", "An expression of one of
the forms e1 >> e2".
CONST_EVAL_TYPE_NUM:
problemMessage: "In constant expressions, operands of this operator must be of type 'num'."
hasPublishedDocs: false
comment: |-
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
for text about "An expression of the form e1 - e2".
CONST_EVAL_TYPE_NUM_STRING:
problemMessage: "In constant expressions, operands of this operator must be of type 'num' or 'String'."
hasPublishedDocs: false
comment: |-
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
for text about "An expression of the form e1 + e2".
CONST_EVAL_TYPE_STRING:
problemMessage: "In constant expressions, operands of this operator must be of type 'String'."
hasPublishedDocs: false
comment: No parameters.
CONST_EVAL_TYPE_TYPE:
problemMessage: "In constant expressions, operands of this operator must be of type 'Type'."
hasPublishedDocs: false
CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE:
problemMessage: Const variables must be initialized with a constant value.
correctionMessage: Try changing the initializer to be a constant expression.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a value that isn't statically
known to be a constant is assigned to a variable that's declared to be a
`const` variable.
#### Example
The following code produces this diagnostic because `x` isn't declared to
be `const`:
```dart
var x = 0;
const y = [!x!];
```
#### Common fixes
If the value being assigned can be declared to be `const`, then change the
declaration:
```dart
const x = 0;
const y = x;
```
If the value can't be declared to be `const`, then remove the `const`
modifier from the variable, possibly using `final` in its place:
```dart
var x = 0;
final y = x;
```
CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE_FROM_DEFERRED_LIBRARY:
problemMessage: "Constant values from a deferred library can't be used to initialize a 'const' variable."
correctionMessage: Try initializing the variable without referencing members of the deferred library, or changing the import to not be deferred.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a `const` variable is
initialized using a `const` variable from a library that is imported using
a deferred import. Constants are evaluated at compile time, and values from
deferred libraries aren't available at compile time.
For more information, check out
[Lazily loading a library](https://dart.dev/language/libraries#lazily-loading-a-library).
#### Example
The following code produces this diagnostic because the variable `pi` is
being initialized using the constant `math.pi` from the library
`dart:math`, and `dart:math` is imported as a deferred library:
```dart
import 'dart:math' deferred as math;
const pi = math.[!pi!];
```
#### Common fixes
If you need to reference the value of the constant from the imported
library, then remove the keyword `deferred`:
```dart
import 'dart:math' as math;
const pi = math.pi;
```
If you don't need to reference the imported constant, then remove the
reference:
```dart
const pi = 3.14;
```
CONST_INSTANCE_FIELD:
problemMessage: Only static fields can be declared as const.
correctionMessage: "Try declaring the field as final, or adding the keyword 'static'."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when an instance field is marked as
being const.
#### Example
The following code produces this diagnostic because `f` is an instance
field:
```dart
class C {
[!const!] int f = 3;
}
```
#### Common fixes
If the field needs to be an instance field, then remove the keyword
`const`, or replace it with `final`:
```dart
class C {
final int f = 3;
}
```
If the field really should be a const field, then make it a static field:
```dart
class C {
static const int f = 3;
}
```
CONST_MAP_KEY_NOT_PRIMITIVE_EQUALITY:
problemMessage: "The type of a key in a constant map can't override the '==' operator, or 'hashCode', but the class '{0}' does."
correctionMessage: "Try using a different value for the key, or removing the keyword 'const' from the map."
hasPublishedDocs: true
comment: |-
Parameters:
0: the type of the entry's key
documentation: |-
#### Description
The analyzer produces this diagnostic when the class of object used as a
key in a constant map literal implements either the `==` operator, the
getter `hashCode`, or both. The implementation of constant maps uses both
the `==` operator and the `hashCode` getter, so any implementation other
than the ones inherited from `Object` requires executing arbitrary code at
compile time, which isn't supported.
#### Examples
The following code produces this diagnostic because the constant map
contains a key whose type is `C`, and the class `C` overrides the
implementation of `==`:
```dart
class C {
const C();
bool operator ==(Object other) => true;
}
const map = {[!C()!] : 0};
```
The following code produces this diagnostic because the constant map
contains a key whose type is `C`, and the class `C` overrides the
implementation of `hashCode`:
```dart
class C {
const C();
int get hashCode => 3;
}
const map = {[!C()!] : 0};
```
#### Common fixes
If you can remove the implementation of `==` and `hashCode` from the
class, then do so:
```dart
class C {
const C();
}
const map = {C() : 0};
```
If you can't remove the implementation of `==` and `hashCode` from the
class, then make the map non-constant:
```dart
class C {
const C();
bool operator ==(Object other) => true;
}
final map = {C() : 0};
```
CONST_NOT_INITIALIZED:
problemMessage: "The constant '{0}' must be initialized."
correctionMessage: Try adding an initialization to the declaration.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the uninitialized final variable
documentation: |-
#### Description
The analyzer produces this diagnostic when a variable that is declared to
be a constant doesn't have an initializer.
#### Example
The following code produces this diagnostic because `c` isn't initialized:
```dart
const [!c!];
```
#### Common fixes
Add an initializer:
```dart
const c = 'c';
```
CONST_SET_ELEMENT_NOT_PRIMITIVE_EQUALITY:
problemMessage: "An element in a constant set can't override the '==' operator, or 'hashCode', but the type '{0}' does."
correctionMessage: "Try using a different value for the element, or removing the keyword 'const' from the set."
previousName: CONST_SET_ELEMENT_TYPE_IMPLEMENTS_EQUALS
hasPublishedDocs: true
comment: |-
Parameters:
0: the type of the element
documentation: |-
#### Description
The analyzer produces this diagnostic when the class of object used as an
element in a constant set literal implements either the `==` operator, the
getter `hashCode`, or both. The implementation of constant sets uses both
the `==` operator and the `hashCode` getter, so any implementation other
than the ones inherited from `Object` requires executing arbitrary code at
compile time, which isn't supported.
#### Example
The following code produces this diagnostic because the constant set
contains an element whose type is `C`, and the class `C` overrides the
implementation of `==`:
```dart
class C {
const C();
bool operator ==(Object other) => true;
}
const set = {[!C()!]};
```
The following code produces this diagnostic because the constant set
contains an element whose type is `C`, and the class `C` overrides the
implementation of `hashCode`:
```dart
class C {
const C();
int get hashCode => 3;
}
const map = {[!C()!]};
```
#### Common fixes
If you can remove the implementation of `==` and `hashCode` from the
class, then do so:
```dart
class C {
const C();
}
const set = {C()};
```
If you can't remove the implementation of `==` and `hashCode` from the
class, then make the set non-constant:
```dart
class C {
const C();
bool operator ==(Object other) => true;
}
final set = {C()};
```
CONST_SPREAD_EXPECTED_LIST_OR_SET:
problemMessage: A list or a set is expected in this spread.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the expression of a spread
operator in a constant list or set evaluates to something other than a list
or a set.
#### Example
The following code produces this diagnostic because the value of `list1` is
`null`, which is neither a list nor a set:
```dart
const dynamic list1 = 42;
const List<int> list2 = [...[!list1!]];
```
#### Common fixes
Change the expression to something that evaluates to either a constant list
or a constant set:
```dart
const dynamic list1 = [42];
const List<int> list2 = [...list1];
```
CONST_SPREAD_EXPECTED_MAP:
problemMessage: A map is expected in this spread.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the expression of a spread
operator in a constant map evaluates to something other than a map.
#### Example
The following code produces this diagnostic because the value of `map1` is
`null`, which isn't a map:
```dart
const dynamic map1 = 42;
const Map<String, int> map2 = {...[!map1!]};
```
#### Common fixes
Change the expression to something that evaluates to a constant map:
```dart
const dynamic map1 = {'answer': 42};
const Map<String, int> map2 = {...map1};
```
CONST_TYPE_PARAMETER:
problemMessage: "Type parameters can't be used in a constant expression."
correctionMessage: Try replacing the type parameter with a different type.
hasPublishedDocs: false
comment: No parameters.
CONST_WITH_NON_CONST:
problemMessage: "The constructor being called isn't a const constructor."
correctionMessage: "Try removing 'const' from the constructor invocation."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the keyword `const` is used to
invoke a constructor that isn't marked with `const`.
#### Example
The following code produces this diagnostic because the constructor in `A`
isn't a const constructor:
```dart
class A {
A();
}
A f() => [!const!] A();
```
#### Common fixes
If it's desirable and possible to make the class a constant class (by
making all of the fields of the class, including inherited fields, final),
then add the keyword `const` to the constructor:
```dart
class A {
const A();
}
A f() => const A();
```
Otherwise, remove the keyword `const`:
```dart
class A {
A();
}
A f() => A();
```
CONST_WITH_NON_CONSTANT_ARGUMENT:
problemMessage: Arguments of a constant creation must be constant expressions.
correctionMessage: "Try making the argument a valid constant, or use 'new' to call the constructor."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a const constructor is invoked
with an argument that isn't a constant expression.
#### Example
The following code produces this diagnostic because `i` isn't a constant:
```dart
class C {
final int i;
const C(this.i);
}
C f(int i) => const C([!i!]);
```
#### Common fixes
Either make all of the arguments constant expressions, or remove the
`const` keyword to use the non-constant form of the constructor:
```dart
class C {
final int i;
const C(this.i);
}
C f(int i) => C(i);
```
CONST_WITH_TYPE_PARAMETERS:
problemMessage: "A constant creation can't use a type parameter as a type argument."
correctionMessage: Try replacing the type parameter with a different type.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a type parameter is used as a
type argument in a `const` invocation of a constructor. This isn't allowed
because the value of the type parameter (the actual type that will be used
at runtime) can't be known at compile time.
#### Example
The following code produces this diagnostic because the type parameter `T`
is being used as a type argument when creating a constant:
```dart
class C<T> {
const C();
}
C<T> newC<T>() => const C<[!T!]>();
```
#### Common fixes
If the type that will be used for the type parameter can be known at
compile time, then remove the use of the type parameter:
```dart
class C<T> {
const C();
}
C<int> newC() => const C<int>();
```
If the type that will be used for the type parameter can't be known until
runtime, then remove the keyword `const`:
```dart
class C<T> {
const C();
}
C<T> newC<T>() => C<T>();
```
CONST_WITH_TYPE_PARAMETERS_CONSTRUCTOR_TEAROFF:
sharedName: CONST_WITH_TYPE_PARAMETERS
problemMessage: "A constant constructor tearoff can't use a type parameter as a type argument."
correctionMessage: Try replacing the type parameter with a different type.
hasPublishedDocs: true
comment: No parameters.
CONST_WITH_TYPE_PARAMETERS_FUNCTION_TEAROFF:
sharedName: CONST_WITH_TYPE_PARAMETERS
problemMessage: "A constant function tearoff can't use a type parameter as a type argument."
correctionMessage: Try replacing the type parameter with a different type.
hasPublishedDocs: true
comment: No parameters.
CONST_WITH_UNDEFINED_CONSTRUCTOR:
problemMessage: "The class '{0}' doesn't have a constant constructor '{1}'."
correctionMessage: Try calling a different constructor.
hasPublishedDocs: false
comment: |-
16.12.2 Const: It is a compile-time error if <i>T.id</i> is not the name of
a constant constructor declared by the type <i>T</i>.
Parameters:
0: the name of the type
1: the name of the requested constant constructor
CONST_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT:
problemMessage: "The class '{0}' doesn't have an unnamed constant constructor."
correctionMessage: Try calling a different constructor.
hasPublishedDocs: false
comment: |-
16.12.2 Const: It is a compile-time error if <i>T.id</i> is not the name of
a constant constructor declared by the type <i>T</i>.
Parameters:
0: the name of the type
CONSTANT_PATTERN_WITH_NON_CONSTANT_EXPRESSION:
problemMessage: The expression of a constant pattern must be a valid constant.
correctionMessage: Try making the expression a valid constant.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a constant pattern has an
expression that isn't a valid constant.
#### Example
The following code produces this diagnostic because the constant pattern
`i` isn't a constant:
```dart
void f(int e, int i) {
switch (e) {
case [!i!]:
break;
}
}
```
#### Common fixes
If the value that should be matched is known, then replace the expression
with a constant:
```dart
void f(int e, int i) {
switch (e) {
case 0:
break;
}
}
```
If the value that should be matched isn't known, then rewrite the code to
not use a pattern:
```dart
void f(int e, int i) {
if (e == i) {}
}
```
CONTINUE_LABEL_INVALID:
previousName: CONTINUE_LABEL_ON_SWITCH
hasPublishedDocs: true
problemMessage: The label used in a 'continue' statement must be defined on either a loop or a switch member.
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when the label in a `continue`
statement resolves to a label on a `switch` statement.
#### Example
The following code produces this diagnostic because the label `l`, used to
label a `switch` statement, is used in the `continue` statement:
```dart
void f(int i) {
l: switch (i) {
case 0:
[!continue l;!]
}
}
```
#### Common fixes
Find a different way to achieve the control flow you need; for example, by
introducing a loop that re-executes the `switch` statement.
COULD_NOT_INFER:
problemMessage: "Couldn't infer type parameter '{0}'.{1}"
hasPublishedDocs: false
comment: |-
Parameters:
0: the name of the type parameter
1: detail text explaining why the type could not be inferred
NEW_WITH_NON_TYPE:
sharedName: CREATION_WITH_NON_TYPE
problemMessage: "The name '{0}' isn't a class."
correctionMessage: Try correcting the name to match an existing class.
isUnresolvedIdentifier: true
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the non-type element
documentation: |-
#### Description
The analyzer produces this diagnostic when an instance creation using
either `new` or `const` specifies a name that isn't defined as a class.
#### Example
The following code produces this diagnostic because `f` is a function
rather than a class:
```dart
int f() => 0;
void g() {
new [!f!]();
}
```
#### Common fixes
If a class should be created, then replace the invalid name with the name
of a valid class:
```dart
int f() => 0;
void g() {
new Object();
}
```
If the name is the name of a function and you want that function to be
invoked, then remove the `new` or `const` keyword:
```dart
int f() => 0;
void g() {
f();
}
```
CONST_WITH_NON_TYPE:
sharedName: CREATION_WITH_NON_TYPE
problemMessage: "The name '{0}' isn't a class."
correctionMessage: Try correcting the name to match an existing class.
isUnresolvedIdentifier: true
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the non-type element
DEFAULT_LIST_CONSTRUCTOR:
removedIn: "3.2"
problemMessage: "The default 'List' constructor isn't available when null safety is enabled."
correctionMessage: "Try using a list literal, 'List.filled' or 'List.generate'."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when it finds a use of the default
constructor for the class `List` in code that has opted in to null safety.
#### Example
Assuming the following code is opted in to null safety, it produces this
diagnostic because it uses the default `List` constructor:
```dart
var l = [!List<int>!]();
```
#### Common fixes
If no initial size is provided, then convert the code to use a list
literal:
```dart
var l = <int>[];
```
If an initial size needs to be provided and there is a single reasonable
initial value for the elements, then use `List.filled`:
```dart
var l = List.filled(3, 0);
```
If an initial size needs to be provided but each element needs to be
computed, then use `List.generate`:
```dart
var l = List.generate(3, (i) => i);
```
DEFAULT_VALUE_IN_REDIRECTING_FACTORY_CONSTRUCTOR:
problemMessage: "Default values aren't allowed in factory constructors that redirect to another constructor."
correctionMessage: Try removing the default value.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a factory constructor that
redirects to another constructor specifies a default value for an optional
parameter.
#### Example
The following code produces this diagnostic because the factory constructor
in `A` has a default value for the optional parameter `x`:
```dart
class A {
factory A([int [!x!] = 0]) = B;
}
class B implements A {
B([int x = 1]) {}
}
```
#### Common fixes
Remove the default value from the factory constructor:
```dart
class A {
factory A([int x]) = B;
}
class B implements A {
B([int x = 1]) {}
}
```
Note that this fix might change the value used when the optional parameter
is omitted. If that happens, and if that change is a problem, then consider
making the optional parameter a required parameter in the factory method:
```dart
class A {
factory A(int x) = B;
}
class B implements A {
B([int x = 1]) {}
}
```
DEFAULT_VALUE_ON_REQUIRED_PARAMETER:
problemMessage: "Required named parameters can't have a default value."
correctionMessage: "Try removing either the default value or the 'required' modifier."
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a named parameter has both the
`required` modifier and a default value. If the parameter is required, then
a value for the parameter is always provided at the call sites, so the
default value can never be used.
#### Example
The following code generates this diagnostic:
```dart
void log({required String [!message!] = 'no message'}) {}
```
#### Common fixes
If the parameter is really required, then remove the default value:
```dart
void log({required String message}) {}
```
If the parameter isn't always required, then remove the `required`
modifier:
```dart
void log({String message = 'no message'}) {}
```
DEFERRED_IMPORT_OF_EXTENSION:
problemMessage: Imports of deferred libraries must hide all extensions.
correctionMessage: Try adding either a show combinator listing the names you need to reference or a hide combinator listing all of the extensions.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a library that is imported using
a deferred import declares an extension that is visible in the importing
library. Extension methods are resolved at compile time, and extensions
from deferred libraries aren't available at compile time.
For more information, check out
[Lazily loading a library](https://dart.dev/language/libraries#lazily-loading-a-library).
#### Example
Given a file `a.dart` that defines a named extension:
```dart
%uri="lib/a.dart"
class C {}
extension E on String {
int get size => length;
}
```
The following code produces this diagnostic because the named extension is
visible to the library:
```dart
import [!'a.dart'!] deferred as a;
void f() {
a.C();
}
```
#### Common fixes
If the library must be imported as `deferred`, then either add a `show`
clause listing the names being referenced or add a `hide` clause listing
all of the named extensions. Adding a `show` clause would look like this:
```dart
import 'a.dart' deferred as a show C;
void f() {
a.C();
}
```
Adding a `hide` clause would look like this:
```dart
import 'a.dart' deferred as a hide E;
void f() {
a.C();
}
```
With the first fix, the benefit is that if new extensions are added to the
imported library, then the extensions won't cause a diagnostic to be
generated.
If the library doesn't need to be imported as `deferred`, or if you need to
make use of the extension method declared in it, then remove the keyword
`deferred`:
```dart
import 'a.dart' as a;
void f() {
a.C();
}
```
DEFINITELY_UNASSIGNED_LATE_LOCAL_VARIABLE:
problemMessage: "The late local variable '{0}' is definitely unassigned at this point."
correctionMessage: Ensure that it is assigned on necessary execution paths.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the variable that is invalid
documentation: |-
#### Description
The analyzer produces this diagnostic when [definite assignment][] analysis
shows that a local variable that's marked as `late` is read before being
assigned.
#### Example
The following code produces this diagnostic because `x` wasn't assigned a
value before being read:
```dart
void f(bool b) {
late int x;
print([!x!]);
}
```
#### Common fixes
Assign a value to the variable before reading from it:
```dart
void f(bool b) {
late int x;
x = b ? 1 : 0;
print(x);
}
```
DISALLOWED_TYPE_INSTANTIATION_EXPRESSION:
problemMessage: Only a generic type, generic function, generic instance method, or generic constructor can have type arguments.
correctionMessage: Try removing the type arguments, or instantiating the type(s) of a generic type, generic function, generic instance method, or generic constructor.
comment: No parameters.
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when an expression with a value that
is anything other than one of the allowed kinds of values is followed by
type arguments. The allowed kinds of values are:
- generic types,
- generic constructors, and
- generic functions, including top-level functions, static and instance
members, and local functions.
#### Example
The following code produces this diagnostic because `i` is a top-level
variable, which isn't one of the allowed cases:
```dart
int i = 1;
void f() {
print([!i!]<int>);
}
```
#### Common fixes
If the referenced value is correct, then remove the type arguments:
```dart
int i = 1;
void f() {
print(i);
}
```
DUPLICATE_AUGMENTATION_IMPORT:
problemMessage: "The library already contains an augmentation with the URI '{0}'."
correctionMessage: Try removing all except one of the duplicated augmentation directives.
hasPublishedDocs: false
comment: |-
Parameters:
0: the URI of the duplicate augmentation
DUPLICATE_CONSTRUCTOR_NAME:
sharedName: DUPLICATE_CONSTRUCTOR
problemMessage: "The constructor with name '{0}' is already defined."
correctionMessage: Try renaming one of the constructors.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the duplicate entity
DUPLICATE_CONSTRUCTOR_DEFAULT:
sharedName: DUPLICATE_CONSTRUCTOR
problemMessage: The unnamed constructor is already defined.
correctionMessage: Try giving one of the constructors a name.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a class declares more than one
unnamed constructor or when it declares more than one constructor with the
same name.
#### Examples
The following code produces this diagnostic because there are two
declarations for the unnamed constructor:
```dart
class C {
C();
[!C!]();
}
```
The following code produces this diagnostic because there are two
declarations for the constructor named `m`:
```dart
class C {
C.m();
[!C.m!]();
}
```
#### Common fixes
If there are multiple unnamed constructors and all of the constructors are
needed, then give all of them, or all except one of them, a name:
```dart
class C {
C();
C.n();
}
```
If there are multiple unnamed constructors and all except one of them are
unneeded, then remove the constructors that aren't needed:
```dart
class C {
C();
}
```
If there are multiple named constructors and all of the constructors are
needed, then rename all except one of them:
```dart
class C {
C.m();
C.n();
}
```
If there are multiple named constructors and all except one of them are
unneeded, then remove the constructors that aren't needed:
```dart
class C {
C.m();
}
```
DUPLICATE_DEFINITION:
problemMessage: "The name '{0}' is already defined."
correctionMessage: Try renaming one of the declarations.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the duplicate entity
documentation: |-
#### Description
The analyzer produces this diagnostic when a name is declared, and there is
a previous declaration with the same name in the same scope.
#### Example
The following code produces this diagnostic because the name `x` is
declared twice:
```dart
int x = 0;
int [!x!] = 1;
```
#### Common fixes
Choose a different name for one of the declarations.
```dart
int x = 0;
int y = 1;
```
DUPLICATE_FIELD_NAME:
problemMessage: The field name '{0}' is already used in this record.
correctionMessage: Try renaming the field.
hasPublishedDocs: true
comment: |-
Parameters:
0: the duplicated name
documentation: |-
#### Description
The analyzer produces this diagnostic when either a record literal or a
record type annotation contains a field whose name is the same as a
previously declared field in the same literal or type.
#### Examples
The following code produces this diagnostic because the record literal has
two fields named `a`:
```dart
var r = (a: 1, [!a!]: 2);
```
The following code produces this diagnostic because the record type
annotation has two fields named `a`, one a positional field and the other
a named field:
```dart
void f((int a, {int [!a!]}) r) {}
```
#### Common fixes
Rename one or both of the fields:
```dart
var r = (a: 1, b: 2);
```
DUPLICATE_FIELD_FORMAL_PARAMETER:
problemMessage: "The field '{0}' can't be initialized by multiple parameters in the same constructor."
correctionMessage: Try removing one of the parameters, or using different fields.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the field
documentation: |-
#### Description
The analyzer produces this diagnostic when there's more than one
initializing formal parameter for the same field in a constructor's
parameter list. It isn't useful to assign a value that will immediately be
overwritten.
#### Example
The following code produces this diagnostic because `this.f` appears twice
in the parameter list:
```dart
class C {
int f;
C(this.f, this.[!f!]) {}
}
```
#### Common fixes
Remove one of the initializing formal parameters:
```dart
class C {
int f;
C(this.f) {}
}
```
DUPLICATE_NAMED_ARGUMENT:
problemMessage: "The argument for the named parameter '{0}' was already specified."
correctionMessage: Try removing one of the named arguments, or correcting one of the names to reference a different named parameter.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the parameter that was duplicated
documentation: |-
#### Description
The analyzer produces this diagnostic when an invocation has two or more
named arguments that have the same name.
#### Example
The following code produces this diagnostic because there are two arguments
with the name `a`:
```dart
void f(C c) {
c.m(a: 0, [!a!]: 1);
}
class C {
void m({int? a, int? b}) {}
}
```
#### Common fixes
If one of the arguments should have a different name, then change the name:
```dart
void f(C c) {
c.m(a: 0, b: 1);
}
class C {
void m({int? a, int? b}) {}
}
```
If one of the arguments is wrong, then remove it:
```dart
void f(C c) {
c.m(a: 1);
}
class C {
void m({int? a, int? b}) {}
}
```
DUPLICATE_PART:
problemMessage: "The library already contains a part with the URI '{0}'."
correctionMessage: Try removing all except one of the duplicated part directives.
hasPublishedDocs: true
comment: |-
Parameters:
0: the URI of the duplicate part
documentation: |-
#### Description
The analyzer produces this diagnostic when a single file is referenced in
multiple part directives.
#### Example
Given a file `part.dart` containing
```dart
%uri="lib/part.dart"
part of lib;
```
The following code produces this diagnostic because the file `part.dart` is
included multiple times:
```dart
library lib;
part 'part.dart';
part [!'part.dart'!];
```
#### Common fixes
Remove all except the first of the duplicated part directives:
```dart
library lib;
part 'part.dart';
```
DUPLICATE_PATTERN_ASSIGNMENT_VARIABLE:
problemMessage: The variable '{0}' is already assigned in this pattern.
correctionMessage: Try renaming the variable.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the variable
documentation: |-
#### Description
The analyzer produces this diagnostic when a single pattern variable is
assigned a value more than once in the same pattern assignment.
#### Example
The following code produces this diagnostic because the variable `a` is
assigned twice in the pattern `(a, a)`:
```dart
int f((int, int) r) {
int a;
(a, [!a!]) = r;
return a;
}
```
#### Common fixes
If you need to capture all of the values, then use a unique variable for
each of the subpatterns being matched:
```dart
int f((int, int) r) {
int a, b;
(a, b) = r;
return a + b;
}
```
If some of the values don't need to be captured, then use a wildcard
pattern `_` to avoid having to bind the value to a variable:
```dart
int f((int, int) r) {
int a;
(_, a) = r;
return a;
}
```
DUPLICATE_PATTERN_FIELD:
problemMessage: The field '{0}' is already matched in this pattern.
correctionMessage: Try removing the duplicate field.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the field
documentation: |-
#### Description
The analyzer produces this diagnostic when a record pattern matches the
same field more than once, or when an object pattern matches the same
getter more than once.
#### Examples
The following code produces this diagnostic because the record field `a`
is matched twice in the same record pattern:
```dart
void f(({int a, int b}) r) {
switch (r) {
case (a: 1, [!a!]: 2):
return;
}
}
```
The following code produces this diagnostic because the getter `f` is
matched twice in the same object pattern:
```dart
void f(Object o) {
switch (o) {
case C(f: 1, [!f!]: 2):
return;
}
}
class C {
int? f;
}
```
#### Common fixes
If the pattern should match for more than one value of the duplicated
field, then use a logical-or pattern:
```dart
void f(({int a, int b}) r) {
switch (r) {
case (a: 1, b: _) || (a: 2, b: _):
break;
}
}
```
If the pattern should match against multiple fields, then change the name
of one of the fields:
```dart
void f(({int a, int b}) r) {
switch (r) {
case (a: 1, b: 2):
return;
}
}
```
DUPLICATE_REST_ELEMENT_IN_PATTERN:
problemMessage: At most one rest element is allowed in a list or map pattern.
correctionMessage: Try removing the duplicate rest element.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when there's more than one rest
pattern in either a list or map pattern. A rest pattern will capture any
values unmatched by other subpatterns, making subsequent rest patterns
unnecessary because there's nothing left to capture.
#### Example
The following code produces this diagnostic because there are two rest
patterns in the list pattern:
```dart
void f(List<int> x) {
if (x case [0, ..., [!...!]]) {}
}
```
#### Common fixes
Remove all but one of the rest patterns:
```dart
void f(List<int> x) {
if (x case [0, ...]) {}
}
```
DUPLICATE_VARIABLE_PATTERN:
problemMessage: The variable '{0}' is already defined in this pattern.
correctionMessage: Try renaming the variable.
hasPublishedDocs: true
comment: |-
Parameters:
0: the name of the variable
documentation: |-
#### Description
The analyzer produces this diagnostic when a branch of a logical-and
pattern declares a variable that is already declared in an earlier branch
of the same pattern.
#### Example
The following code produces this diagnostic because the variable `a` is
declared in both branches of the logical-and pattern:
```dart
void f((int, int) r) {
if (r case (var a, 0) && (0, var [!a!])) {
print(a);
}
}
```
#### Common fixes
If you need to capture the matched value in multiple branches, then change
the names of the variables so that they are unique:
```dart
void f((int, int) r) {
if (r case (var a, 0) && (0, var b)) {
print(a + b);
}
}
```
If you only need to capture the matched value on one branch, then remove
the variable pattern from all but one branch:
```dart
void f((int, int) r) {
if (r case (var a, 0) && (0, _)) {
print(a);
}
}
```
EMPTY_MAP_PATTERN:
problemMessage: A map pattern must have at least one entry.
correctionMessage: Try replacing it with an object pattern 'Map()'.
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a map pattern is empty.
#### Example
The following code produces this diagnostic because the map pattern
is empty:
```dart
void f(Map<int, String> x) {
if (x case [!{}!]) {}
}
```
#### Common fixes
If the pattern should match any map, then replace it with an object
pattern:
```dart
void f(Map<int, String> x) {
if (x case Map()) {}
}