594efdd63c
Change-Id: If31cfea7c3dc3379cc0e8eda454ac9fdec4a348d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503942 Reviewed-by: Connie Ooi <connieooi@google.com> Auto-Submit: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
31507 lines
930 KiB
YAML
31507 lines
930 KiB
YAML
# 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.
|
|
|
|
# Run
|
|
#
|
|
# dart run pkg/analyzer/tool/messages/generate.dart
|
|
#
|
|
# to regenerate messages after having edited this 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 a map called `parameters`; each map key is of
|
|
# the form `TYPE NAME`, and each map value is a comment describing the
|
|
# parameter. Placeholders in the `problemMessage` and `correctionMessage`
|
|
# strings take the form `#NAME`.
|
|
#
|
|
# If a diagnostic takes no parameters, it must have an entry of the
|
|
# form `parameters: none`.
|
|
#
|
|
# Errors can be reported in two ways:
|
|
#
|
|
# - The old way (deprecated): at the time the analyzer reports the
|
|
# error, it supplies substitutions to take the place of the `#NAME`
|
|
# placeholders in the form of a list whose order matches the order
|
|
# of the key/value pairs in the `parameters` map. The number and
|
|
# types of the supplied values are checked at runtime.
|
|
#
|
|
# - The new way: at the time the analyzer reports the error, it calls
|
|
# the error code's `withArguments` method, supplying the
|
|
# substitutions in the form of named parameters. The number and
|
|
# types of the supplied values are checked at compile time.
|
|
|
|
AnalysisOptionsErrorCode:
|
|
includedFileParseError:
|
|
type: compileTimeError
|
|
parameters:
|
|
String includingFilePath: the path of the file containing the error
|
|
int startOffset: the starting offset of the text in the file that contains the error
|
|
int endOffset: the ending offset of the text in the file that contains the error
|
|
String errorMessage: the error message
|
|
problemMessage: "#errorMessage in #includingFilePath(#startOffset..#endOffset)"
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the content of a file that is
|
|
included into an analysis options file isn't valid YAML.
|
|
|
|
#### Example
|
|
|
|
Given a file named `shared.yaml` that contains:
|
|
|
|
```yaml
|
|
// %uri="shared.yaml"
|
|
analyzer:
|
|
enable-experiment:
|
|
- augmentations
|
|
enable-experiment:
|
|
- dot-shorthands
|
|
```
|
|
|
|
The following code produces this diagnostic because the included file
|
|
isn't valid YAML: the analyzer map contains duplicate `enable-experiment`
|
|
keys.
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
include: [!shared.yaml!]
|
|
analyzer:
|
|
enable-experiment:
|
|
- enhanced-parts
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the file is intended to be included, then correct the included file to
|
|
be valid YAML:
|
|
|
|
```yaml
|
|
// %uri="shared.yaml"
|
|
analyzer:
|
|
enable-experiment:
|
|
- augmentations
|
|
- dot-shorthands
|
|
```
|
|
|
|
If the file isn't intended to be included, then remove the `include` key:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
enable-experiment:
|
|
- enhanced-parts
|
|
```
|
|
comment: |-
|
|
An error code indicating that there is a syntactic error in the included
|
|
file.
|
|
parseError:
|
|
type: compileTimeError
|
|
parameters:
|
|
String errorMessage: the error message from the parse error
|
|
problemMessage: "#errorMessage"
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the contents of an analysis
|
|
options file isn't valid YAML.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `analyzer` section
|
|
has two `enable-experiment` keys:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
enable-experiment:
|
|
- augmentations
|
|
[!enable-experiment!]:
|
|
- dot-shorthands
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Correct the file to be valid YAML:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
enable-experiment:
|
|
- augmentations
|
|
- dot-shorthands
|
|
```
|
|
comment: |-
|
|
An error code indicating that there is a syntactic error in the file.
|
|
AnalysisOptionsWarningCode:
|
|
analysisOptionDeprecated:
|
|
type: staticWarning
|
|
parameters:
|
|
String optionName: the option name
|
|
problemMessage: "The option '#optionName' is no longer supported."
|
|
correctionMessage: Try removing the option.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an option in an analysis
|
|
options file is deprecated.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the top-level key
|
|
`errors` is deprecated:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
[!errors!]:
|
|
dead_code: ignore
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a replacement option or format exists, update the file to use it:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
dead_code: ignore
|
|
```
|
|
|
|
If no replacement is available, remove the deprecated option.
|
|
comment: |-
|
|
An error code indicating that the given option is deprecated.
|
|
analysisOptionDeprecatedWithReplacement:
|
|
type: staticWarning
|
|
parameters:
|
|
String optionName: the option name
|
|
String replacementOptionName: the replacement option name
|
|
sharedName: analysisOptionDeprecated
|
|
problemMessage: "The option '#optionName' is no longer supported."
|
|
correctionMessage: "Try using the new '#replacementOptionName' option."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating that the given option is deprecated.
|
|
deprecatedLint:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
problemMessage: The lint rule '#ruleName' is deprecated and shouldn't be enabled.
|
|
correctionMessage: Try removing '#ruleName'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enabled lint rule is
|
|
deprecated.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the rule
|
|
`always_specify_types` is deprecated:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- [!always_specify_types!]
|
|
- annotate_overrides
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a replacement rule exists, enable it:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- annotate_overrides
|
|
- specify_nonobvious_property_types
|
|
```
|
|
|
|
If no replacement rule exists, remove the deprecated lint rule from the
|
|
list:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- annotate_overrides
|
|
```
|
|
comment: |-
|
|
A hint code indicating reference to a deprecated lint.
|
|
deprecatedLintWithReplacement:
|
|
type: staticWarning
|
|
parameters:
|
|
String deprecatedRuleName: the deprecated lint name
|
|
String replacementRuleName: the replacing rule name
|
|
problemMessage: "The lint rule '#deprecatedRuleName' is deprecated and replaced by '#replacementRuleName'."
|
|
correctionMessage: "Try replacing '#deprecatedRuleName' with '#replacementRuleName'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A hint code indicating reference to a deprecated lint.
|
|
duplicateRule:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
problemMessage: "The rule '#ruleName' is already enabled and doesn't need to be enabled again."
|
|
correctionMessage: "Try removing all but one occurrence of the rule."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the same lint rule is listed
|
|
more than once in the linter/rules section.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the lint rule
|
|
`avoid_print` appears twice in the list of enabled rules:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- avoid_print
|
|
- [!avoid_print!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the duplicates:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- avoid_print
|
|
```
|
|
comment: |-
|
|
Duplicate rules.
|
|
includedFileWarning:
|
|
type: staticWarning
|
|
parameters:
|
|
String includingFilePath: the path of the file containing the warnings
|
|
int startOffset: the starting offset of the text in the file that contains the warning
|
|
int endOffset: the ending offset of the text in the file that contains the warning
|
|
String warningMessage: the warning message
|
|
problemMessage: "Warning in the included options file #includingFilePath(#startOffset..#endOffset): #warningMessage"
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an analysis options file
|
|
contains an `include` key, and the included file contains a warning.
|
|
|
|
#### Example
|
|
|
|
Given a file named `shared.yaml` that contains:
|
|
|
|
```yaml
|
|
// %uri="shared.yaml"
|
|
linter:
|
|
rules:
|
|
- undefined_lint_rule
|
|
```
|
|
|
|
The following code produces this diagnostic because the file `shared.yaml`
|
|
has a warning that the rule `undefined_lint_rule` doesn't exist:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
include: [!shared.yaml!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the included file can be fixed, then fix the warning in it.
|
|
|
|
If the included file can't be fixed, then don't include it.
|
|
comment: |-
|
|
An error code indicating a specified include file has a warning.
|
|
includeFileNotFound:
|
|
type: staticWarning
|
|
parameters:
|
|
String includedUri: the URI of the file to be included
|
|
String includingFilePath: the path of the file containing the include directive
|
|
String contextRootPath: the path of the context being analyzed
|
|
problemMessage: "The URI '#includedUri' included in '#includingFilePath' can't be found when analyzing '#contextRootPath'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `include` key in an analysis
|
|
options file specifies a URI that either can't be resolved or doesn't
|
|
exist.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the URI refers to a
|
|
package that doesn't exist:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
include: package:lint/recommended.yaml
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the URI is incorrect, replace it with a correct URI:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
include: package:lints/recommended.yaml
|
|
```
|
|
|
|
If the URI is correct but the package isn't a dependency, add a
|
|
`dev_dependency` for the package to the `pubspec.yaml` file and run
|
|
`dart pub get` or `flutter pub get`.
|
|
comment: |-
|
|
An error code indicating a specified include file could not be found.
|
|
incompatibleLint:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String incompatibleRules: the incompatible rules
|
|
problemMessage: "The rule '#ruleName' is incompatible with '#incompatibleRules'."
|
|
correctionMessage: "Try removing all but one of the incompatible rules."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when two specified lint rules are
|
|
incompatible, such as when they enforce opposite styles.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the rules
|
|
`prefer_single_quotes` and `prefer_double_quotes` are incompatible with
|
|
each other:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- prefer_single_quotes
|
|
- [!prefer_double_quotes!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the incompatible rules:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- prefer_single_quotes
|
|
```
|
|
comment: |-
|
|
An error code indicating an incompatible rule.
|
|
|
|
The incompatible rules must be included by context messages.
|
|
incompatibleLintFiles:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String incompatibleRules: the incompatible rules
|
|
sharedName: incompatibleLint
|
|
problemMessage: "The rule '#ruleName' is incompatible with #incompatibleRules."
|
|
correctionMessage: "Try locally disabling all but one of the conflicting rules or removing one of the incompatible files."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating an incompatible rule.
|
|
|
|
The files that enable the referenced rules must be included by context messages.
|
|
incompatibleLintIncluded:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String incompatibleRules: the incompatible rules
|
|
int numIncludingFiles: the number of files that include the incompatible rule
|
|
String pluralSuffix: plural suffix for the word "file"
|
|
sharedName: incompatibleLint
|
|
problemMessage: "The rule '#ruleName' is incompatible with #incompatibleRules, which is included from #numIncludingFiles file#pluralSuffix."
|
|
correctionMessage: "Try locally disabling all but one of the conflicting rules or removing one of the incompatible files."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating an incompatible rule.
|
|
|
|
invalidOption:
|
|
type: staticWarning
|
|
parameters:
|
|
String optionName: the option name
|
|
String detailMessage: the detail message
|
|
problemMessage: "Invalid option specified for '#optionName': #detailMessage"
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an option is specified and the
|
|
value of the option is invalid.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `fail` isn't a valid
|
|
severity for a diagnostic:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
dead_code: [!fail!]
|
|
prefer_single_quotes: warning
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you specify the option, provide a valid value for it:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
dead_code: error
|
|
prefer_single_quotes: warning
|
|
```
|
|
|
|
If you don't need the option, remove it:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
prefer_single_quotes: warning
|
|
```
|
|
comment: |-
|
|
An error code indicating that a plugin is being configured with an invalid
|
|
value for an option and a detail message is provided.
|
|
invalidSectionFormat:
|
|
type: staticWarning
|
|
parameters:
|
|
String sectionName: the section name
|
|
problemMessage: "Invalid format for the '#sectionName' section."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an analysis options file
|
|
contains a configuration section (key) whose content is not in the
|
|
expected data structure or format. For example, this occurs when the
|
|
configuration requires a map but is provided a list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `errors` section
|
|
expects to have a map as its value:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
- dead_code
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the value to be of the appropriate format:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
dead_code: error
|
|
```
|
|
comment: |-
|
|
An error code indicating an invalid format for an options file section.
|
|
multiplePlugins:
|
|
type: staticWarning
|
|
parameters:
|
|
String firstPluginName: the name of the first plugin
|
|
problemMessage: "Multiple plugins can't be enabled."
|
|
correctionMessage: "Remove all plugins following the first, '#firstPluginName'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
An error code indicating multiple plugins have been specified as enabled.
|
|
pluginsInInnerOptions:
|
|
type: staticWarning
|
|
parameters:
|
|
String contextRoot: the root of the analysis context
|
|
problemMessage: "Plugins can only be specified in the root of a pub workspace or the root of a package that isn't in a workspace."
|
|
correctionMessage: "Try specifying plugins in an analysis options file at '#contextRoot'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when analyzer plugins are defined in
|
|
an analysis options file other than the `analysis_options.yaml` at the
|
|
root of the package.
|
|
|
|
#### Example
|
|
|
|
Given an `analysis_options.yaml` file located in a subdirectory of the
|
|
package root, the following code produces this diagnostic because it
|
|
attempts to define plugins there:
|
|
|
|
```yaml
|
|
// %uri="inner/analysis_options.yaml"
|
|
[!plugins!]:
|
|
one: ^1.0.0
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the list of plugins from the file.
|
|
comment: |-
|
|
An error code indicating plugins have been specified in an "inner"
|
|
analysis options file.
|
|
recursiveIncludeFile:
|
|
type: staticWarning
|
|
parameters:
|
|
String includedUri: the URI of the file to be included
|
|
String includingFilePath: the path of the file containing the include directive
|
|
problemMessage: "The URI '#includedUri' included in '#includingFilePath' includes '#includingFilePath', creating a circular reference."
|
|
correctionMessage: "Try changing the chain of 'include's to break the circularity."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an analysis options file,
|
|
directly or indirectly, includes itself.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the file directly
|
|
includes itself:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
include: [!analysis_options.yaml!]
|
|
```
|
|
|
|
Given a file named `shared_options.yaml` that contains:
|
|
|
|
```yaml
|
|
// %uri="shared_options.yaml"
|
|
include: analysis_options.yaml
|
|
```
|
|
|
|
The following code produces this diagnostic because the file indirectly
|
|
includes itself:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
include: [!shared_options.yaml!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change at least one of the files in order to break the circularity.
|
|
comment: |-
|
|
An error code indicating a specified include file includes itself recursively.
|
|
removedLint:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String sdkVersion: the SDK version in which the lint was removed
|
|
problemMessage: "'#ruleName' was removed in Dart '#sdkVersion'"
|
|
correctionMessage: "Try removing the reference to '#ruleName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an analysis options file
|
|
enables a lint that is no longer supported.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the lint
|
|
`always_declare_return_types` is no longer supported:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- [!always_declare_return_types!]
|
|
- annotate_overrides
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the reference to the removed lint rule:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- annotate_overrides
|
|
```
|
|
comment: |-
|
|
An error code indicating a removed lint rule.
|
|
replacedLint:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String sdkVersion: the SDK version in which the lint was removed
|
|
String replacingLintName: the name of a replacing lint
|
|
problemMessage: "'#ruleName' was replaced by '#replacingLintName' in Dart '#sdkVersion'."
|
|
correctionMessage: "Replace '#ruleName' with '#replacingLintName'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
An error code indicating a removed lint rule.
|
|
undefinedLint:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
problemMessage: "'#ruleName' isn't a recognized lint rule."
|
|
correctionMessage: "Try using the name of a recognized lint rule."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an analysis options file
|
|
attempts to enable a lint rule that is not defined.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because
|
|
`implementation_import` isn't a known lint:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- annotate_overrides
|
|
- [!implementation_import!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name of the lint was mistyped, then correct the name.
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- annotate_overrides
|
|
- implementation_imports
|
|
```
|
|
|
|
If there is no lint corresponding to the flagged entry, then remove the
|
|
undefined lint:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- annotate_overrides
|
|
```
|
|
comment: |-
|
|
An error code indicating an undefined lint rule.
|
|
unrecognizedErrorCode:
|
|
type: staticWarning
|
|
parameters:
|
|
String codeName: the unrecognized error code
|
|
problemMessage: "'#codeName' isn't a recognized diagnostic code."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the analyzer/errors section in
|
|
an analysis options file contains a diagnostic code that is not valid.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the diagnostic
|
|
`implementation_import` isn't defined:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
annotate_overrides: error
|
|
[!implementation_import!]: warning
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the diagnostic being specified has a different name, then replace the
|
|
name:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
annotate_overrides: error
|
|
implementation_imports: warning
|
|
```
|
|
|
|
If there is no diagnostic, then remove the name:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
annotate_overrides: error
|
|
```
|
|
comment: |-
|
|
An error code indicating that an unrecognized error code is being used to
|
|
specify an error filter.
|
|
unsupportedOptionWithoutValues:
|
|
type: staticWarning
|
|
parameters:
|
|
String sectionName: the section name
|
|
String optionKey: the unsupported option key
|
|
sharedName: unsupportedOption
|
|
problemMessage: "The option '#optionKey' isn't supported by '#sectionName'."
|
|
correctionMessage: Try removing the option.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating that a plugin is being configured with an
|
|
unsupported option and legal options are provided.
|
|
unsupportedOptionWithLegalValue:
|
|
type: staticWarning
|
|
parameters:
|
|
String sectionName: the section name
|
|
String optionKey: the unsupported option key
|
|
String legalValue: the legal value
|
|
sharedName: unsupportedOption
|
|
problemMessage: "The option '#optionKey' isn't supported by '#sectionName'."
|
|
correctionMessage: "Try using the only supported option: '#legalValue', or removing the option."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an unsupported option is
|
|
specified.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `experiments` isn't a
|
|
supported option:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
[!experiments!]:
|
|
- augmentations
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended to use a supported option, then replace the unsupported
|
|
option with the supported one:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
enable-experiment:
|
|
- augmentations
|
|
```
|
|
|
|
If no option exists for your intended purpose, then remove the unsupported
|
|
option:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
```
|
|
comment: |-
|
|
An error code indicating that a YAML section is being configured with an
|
|
unsupported option where there is just one legal value.
|
|
unsupportedOptionWithLegalValues:
|
|
type: staticWarning
|
|
parameters:
|
|
String sectionName: the section name
|
|
String optionKey: the unsupported option key
|
|
String legalValues: legal values
|
|
sharedName: unsupportedOption
|
|
problemMessage: "The option '#optionKey' isn't supported by '#sectionName'."
|
|
correctionMessage: "Try using one of the supported options: #legalValues."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating that a YAML section is being configured with an
|
|
unsupported option and legal options are provided.
|
|
unsupportedValue:
|
|
type: staticWarning
|
|
parameters:
|
|
String optionName: the option name
|
|
String invalidValue: the unsupported value
|
|
String legalValues: legal values
|
|
problemMessage: "The value '#invalidValue' isn't supported by '#optionName'."
|
|
correctionMessage: "Try using one of the supported values: #legalValues."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an analysis options file
|
|
contains a valid option and the value of that option is not a valid value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `fatal` isn't a valid
|
|
severity:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
dead_code: [!fatal!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a valid value specifies the intended behavior, then replace the
|
|
unsupported value with it:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
dead_code: error
|
|
```
|
|
|
|
If there is no valid value to use, then remove the option:
|
|
|
|
```yaml
|
|
// %uri="analysis_options.yaml"
|
|
analyzer:
|
|
errors:
|
|
```
|
|
comment: |-
|
|
An error code indicating that an option entry is being configured with an
|
|
unsupported value.
|
|
CompileTimeErrorCode:
|
|
abstractFieldConstructorInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: abstractFieldInitializer
|
|
problemMessage: "Abstract fields can't have initializers."
|
|
correctionMessage: "Try removing the field initializer or the 'abstract' keyword from the field declaration."
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
```
|
|
abstractFieldInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Abstract fields can't have initializers."
|
|
correctionMessage: "Try removing the initializer or the 'abstract' keyword."
|
|
hasPublishedDocs: true
|
|
abstractSuperMemberReference:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberKind: the display name for the kind of the found abstract member
|
|
String name: the name of the member
|
|
problemMessage: "The #memberKind '#name' is always abstract in the supertype."
|
|
hasPublishedDocs: true
|
|
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.
|
|
ambiguousExport:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the ambiguous element
|
|
Uri firstUri: the name of the first library in which the type is found
|
|
Uri secondUri: the name of the second library in which the type is found
|
|
problemMessage: "The name '#name' is defined in the libraries '#firstUri' and '#secondUri'."
|
|
correctionMessage: Try removing the export of one of the libraries, or explicitly hiding the name in one of the export directives.
|
|
hasPublishedDocs: true
|
|
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;
|
|
```
|
|
ambiguousExtensionMemberAccessTwo:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the member
|
|
Element firstExtension: the name of the first declaring extension
|
|
Element secondExtension: the names of the second declaring extension
|
|
sharedName: ambiguousExtensionMemberAccess
|
|
problemMessage: "A member named '#name' is defined in '#firstExtension' and '#secondExtension', and neither is more specific."
|
|
correctionMessage: Try using an extension override to specify the extension you want to be chosen.
|
|
hasPublishedDocs: true
|
|
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);
|
|
}
|
|
```
|
|
ambiguousExtensionMemberAccessThreeOrMore:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the member
|
|
String extensions: the names of the declaring extensions
|
|
sharedName: ambiguousExtensionMemberAccess
|
|
problemMessage: "A member named '#name' is defined in #extensions, and none are more specific."
|
|
correctionMessage: Try using an extension override to specify the extension you want to be chosen.
|
|
hasPublishedDocs: true
|
|
ambiguousImport:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the ambiguous type
|
|
String libraries: the names of the libraries that the type is found
|
|
problemMessage: "The name '#name' is defined in the libraries #libraries."
|
|
correctionMessage: "Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports."
|
|
hasPublishedDocs: true
|
|
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(A a, [!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(A a, 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(A a, 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.A a, a.C c1, b.C c2) {}
|
|
```
|
|
ambiguousSetOrMapLiteralBoth:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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};
|
|
```
|
|
ambiguousSetOrMapLiteralEither:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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;
|
|
}
|
|
```
|
|
anonymousMethodWrongParameterType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type receiverType: the name of the type of the receiver
|
|
Type parameterType: the name of the declared parameter type
|
|
experiment: anonymous-methods
|
|
problemMessage: The receiver type '#receiverType' must be assignable to the formal parameter type '#parameterType' in an anonymous method.
|
|
correctionMessage: Try removing the parameter type, or make it a supertype of the receiver type.
|
|
hasPublishedDocs: false
|
|
argumentTypeNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualStaticType: the name of the actual argument type
|
|
Type expectedStaticType: the name of the expected type
|
|
String additionalInfo: additional information, if any, when problem is associated with records
|
|
problemMessage: "The argument type '#actualStaticType' can't be assigned to the parameter type '#expectedStaticType'. #additionalInfo"
|
|
hasPublishedDocs: true
|
|
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);
|
|
```
|
|
assertInRedirectingConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A redirecting constructor can't have an 'assert' initializer."
|
|
hasPublishedDocs: true
|
|
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() {}
|
|
}
|
|
```
|
|
assignmentToConst:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant variables can't be assigned a value after initialization."
|
|
correctionMessage: "Try removing the assignment, or remove the modifier 'const' from the variable."
|
|
hasPublishedDocs: true
|
|
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);
|
|
}
|
|
```
|
|
assignmentToFinal:
|
|
type: compileTimeError
|
|
parameters:
|
|
String variableName: the name of the final variable
|
|
problemMessage: "'#variableName' can't be used as a setter because it's final."
|
|
correctionMessage: "Try finding a different setter, or making '#variableName' non-final."
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
```
|
|
assignmentToFinalLocal:
|
|
type: compileTimeError
|
|
parameters:
|
|
String variableName: the name of the variable
|
|
problemMessage: "The final variable '#variableName' can only be set once."
|
|
correctionMessage: "Try making '#variableName' non-final."
|
|
hasPublishedDocs: true
|
|
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);
|
|
}
|
|
```
|
|
assignmentToFinalNoSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String variableName: the name of the reference
|
|
String className: the name of the class
|
|
problemMessage: "There isn't a setter named '#variableName' in class '#className'."
|
|
correctionMessage: Try correcting the name to reference an existing setter, or declare the setter.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
```
|
|
assignmentToFunction:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Functions can't be assigned a value."
|
|
hasPublishedDocs: true
|
|
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 = () {};
|
|
}
|
|
```
|
|
assignmentToMethod:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Methods can't be assigned a value."
|
|
hasPublishedDocs: true
|
|
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.
|
|
assignmentToType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Types can't be assigned a value."
|
|
hasPublishedDocs: true
|
|
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);
|
|
}
|
|
```
|
|
asyncForInWrongContext:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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);
|
|
}
|
|
}
|
|
```
|
|
augmentationExtendsClauseAlreadyPresent:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
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.
|
|
hasPublishedDocs: false
|
|
augmentationModifierExtra:
|
|
type: compileTimeError
|
|
parameters:
|
|
String modifier: the lexeme of the modifier.
|
|
experiment: augmentations
|
|
problemMessage: The augmentation has the '#modifier' modifier that the declaration doesn't have.
|
|
correctionMessage: Try removing the '#modifier' modifier, or adding it to the declaration.
|
|
hasPublishedDocs: false
|
|
augmentationModifierMissing:
|
|
type: compileTimeError
|
|
parameters:
|
|
String modifier: the lexeme of the modifier.
|
|
experiment: augmentations
|
|
problemMessage: The augmentation is missing the '#modifier' modifier that the declaration has.
|
|
correctionMessage: Try adding the '#modifier' modifier, or removing it from the declaration.
|
|
hasPublishedDocs: false
|
|
augmentationNamedFormalParameterExtra:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the formal parameter.
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation has a named formal parameter '#name', but the declaration doesn't."
|
|
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
|
hasPublishedDocs: false
|
|
augmentationNamedFormalParameterMissing:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the formal parameter.
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation is missing the named formal parameter '#name' from the declaration."
|
|
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
|
hasPublishedDocs: false
|
|
augmentationOptionalPositionalFormalParameterCount:
|
|
type: compileTimeError
|
|
parameters:
|
|
int expectedCount: the number of optional positional formal parameters in the declaration.
|
|
int actualCount: the number of optional positional formal parameters in the augmentation.
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation has #actualCount optional positional formal parameters, but the declaration has #expectedCount."
|
|
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
|
hasPublishedDocs: false
|
|
augmentationPositionalFormalParameterName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String expectedName: the name from a preceding declaration.
|
|
String actualName: the name in the augmentation.
|
|
experiment: augmentations
|
|
problemMessage: "The parameter name '#actualName' must either match the name '#expectedName' from a preceding declaration or be '_'."
|
|
correctionMessage: "Try changing the name to '#expectedName', or changing it to '_'."
|
|
hasPublishedDocs: false
|
|
augmentationOfDifferentDeclarationKind:
|
|
type: compileTimeError
|
|
parameters:
|
|
String declarationKind: the name of the declaration kind.
|
|
String augmentationKind: the name of the augmentation kind.
|
|
experiment: augmentations
|
|
problemMessage: "Can't augment a #declarationKind with a #augmentationKind."
|
|
correctionMessage: Try changing the augmentation to match the declaration kind.
|
|
hasPublishedDocs: false
|
|
augmentationTypeParameterBound:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
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
|
|
augmentationTypeParameterCount:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
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
|
|
augmentationTypeParameterName:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
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
|
|
augmentationWithoutDeclaration:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
problemMessage: The declaration being augmented doesn't exist.
|
|
correctionMessage: Try changing the augmentation to match an existing declaration.
|
|
hasPublishedDocs: false
|
|
augmentationWithoutGetterDeclaration:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the getter
|
|
sharedName: augmentationWithoutDeclaration
|
|
experiment: augmentations
|
|
problemMessage: "This augmentation induces a getter, but no getter declaration named '#name' exists to augment."
|
|
correctionMessage: Try changing the augmentation to match an existing getter declaration.
|
|
hasPublishedDocs: false
|
|
augmentationWithoutSetterDeclaration:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the setter
|
|
sharedName: augmentationWithoutDeclaration
|
|
experiment: augmentations
|
|
problemMessage: "This augmentation induces a setter, but no setter declaration named '#name' exists to augment."
|
|
correctionMessage: Try changing the augmentation to match an existing setter declaration.
|
|
hasPublishedDocs: false
|
|
augmentationOfMixinApplicationClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
problemMessage: "Mixin application classes can't be augmented."
|
|
correctionMessage: Try removing the 'augment' keyword, or making the target a normal class.
|
|
hasPublishedDocs: false
|
|
augmentationRequiredPositionalFormalParameterCount:
|
|
type: compileTimeError
|
|
parameters:
|
|
int expectedCount: the number of required positional formal parameters in the declaration.
|
|
int actualCount: the number of required positional formal parameters in the augmentation.
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation has #actualCount required positional formal parameters, but the declaration has #expectedCount."
|
|
correctionMessage: Try changing the augmentation's formal parameters to match the declaration.
|
|
hasPublishedDocs: false
|
|
augmentationInducedGetterReturnTypeMismatch:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type expectedType: the return type of the getter being augmented
|
|
Type actualType: the return type of the induced getter
|
|
sharedName: augmentationReturnTypeMismatch
|
|
experiment: augmentations
|
|
problemMessage: "The getter induced by this augmentation has return type '#actualType', but the getter being augmented has return type '#expectedType'."
|
|
correctionMessage: Try changing the augmentation's type to match the getter being augmented.
|
|
hasPublishedDocs: false
|
|
augmentationInducedGetterAlreadyComplete:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: declarationAlreadyComplete
|
|
experiment: augmentations
|
|
problemMessage: "The getter induced by this augmentation is complete, but the getter being augmented is already complete."
|
|
correctionMessage: Try removing the augmentation, or making one of the declarations 'abstract'.
|
|
hasPublishedDocs: false
|
|
augmentationInducedSetterAlreadyComplete:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: declarationAlreadyComplete
|
|
experiment: augmentations
|
|
problemMessage: "The setter induced by this augmentation is complete, but the setter being augmented is already complete."
|
|
correctionMessage: Try removing the augmentation, or making one of the declarations 'abstract'.
|
|
hasPublishedDocs: false
|
|
augmentationReturnTypeMismatch:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type expectedType: the return type of the declaration
|
|
Type actualType: the return type of the augmentation
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation's return type '#actualType' must be the same as the introductory declaration's return type '#expectedType'."
|
|
correctionMessage: Try changing the augmentation's return type to match the declaration.
|
|
hasPublishedDocs: false
|
|
augmentedExpressionIsNotSetter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
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
|
|
augmentedExpressionIsSetter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
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
|
|
augmentedExpressionNotOperator:
|
|
type: compileTimeError
|
|
parameters:
|
|
String operator: the lexeme of the operator.
|
|
experiment: augmentations
|
|
problemMessage: The enclosing augmentation doesn't augment the operator '#operator'.
|
|
correctionMessage: Try augmenting or invoking the correct operator.
|
|
hasPublishedDocs: false
|
|
augmentsConstantVariable:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
problemMessage: "Const variables can't be augmented."
|
|
correctionMessage: "Try removing the augmentation, or changing the const variable to a final variable."
|
|
hasPublishedDocs: false
|
|
awaitInLateLocalVariableInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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;
|
|
}
|
|
```
|
|
awaitInWrongContext:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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.)
|
|
awaitOfIncompatibleType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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;
|
|
}
|
|
```
|
|
baseClassImplementedOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String implementedClassName: the name of the base class being implemented
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The class '#implementedClassName' can't be implemented outside of its library because it's a base class."
|
|
hasPublishedDocs: true
|
|
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 {}
|
|
```
|
|
baseMixinImplementedOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String implementedMixinName: the name of the base mixin being implemented
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The mixin '#implementedMixinName' can't be implemented outside of its library because it's a base mixin."
|
|
hasPublishedDocs: true
|
|
bodyMightCompleteNormally:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type returnType: the name of the return type
|
|
problemMessage: The body might complete normally, causing 'null' to be returned, but the return type, '#returnType', is a potentially non-nullable type.
|
|
correctionMessage: Try adding either a return or a throw statement at the end.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
breakLabelOnSwitchMember:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A break label resolves to the 'case' or 'default' statement.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
builtInIdentifierAsType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String token: the built-in identifier that is being used
|
|
problemMessage: The built-in identifier '#token' can't be used as a type.
|
|
correctionMessage: Try correcting the name to match an existing type.
|
|
hasPublishedDocs: true
|
|
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
|
|
%ignore=undefined_class
|
|
[!import!]<int> x = [];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the built-in identifier with the name of a valid type:
|
|
|
|
```dart
|
|
List<int> x = [];
|
|
```
|
|
builtInIdentifierAsExtensionName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the built-in identifier that is being used
|
|
sharedName: builtInIdentifierInDeclaration
|
|
problemMessage: "The built-in identifier '#name' can't be used as an extension name."
|
|
correctionMessage: Try choosing a different name for the extension.
|
|
hasPublishedDocs: true
|
|
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.
|
|
builtInIdentifierAsExtensionTypeName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the built-in identifier that is being used
|
|
sharedName: builtInIdentifierInDeclaration
|
|
problemMessage: "The built-in identifier '#name' can't be used as an extension type name."
|
|
correctionMessage: Try choosing a different name for the extension type.
|
|
hasPublishedDocs: true
|
|
builtInIdentifierAsPrefixName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the built-in identifier that is being used
|
|
sharedName: builtInIdentifierInDeclaration
|
|
problemMessage: "The built-in identifier '#name' can't be used as a prefix name."
|
|
correctionMessage: Try choosing a different name for the prefix.
|
|
hasPublishedDocs: true
|
|
builtInIdentifierAsTypeName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the built-in identifier that is being used
|
|
sharedName: builtInIdentifierInDeclaration
|
|
problemMessage: "The built-in identifier '#name' can't be used as a type name."
|
|
correctionMessage: Try choosing a different name for the type.
|
|
hasPublishedDocs: true
|
|
builtInIdentifierAsTypeParameterName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the built-in identifier that is being used
|
|
sharedName: builtInIdentifierInDeclaration
|
|
problemMessage: "The built-in identifier '#name' can't be used as a type parameter name."
|
|
correctionMessage: Try choosing a different name for the type parameter.
|
|
hasPublishedDocs: true
|
|
builtInIdentifierAsTypedefName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the built-in identifier that is being used
|
|
sharedName: builtInIdentifierInDeclaration
|
|
problemMessage: "The built-in identifier '#name' can't be used as a typedef name."
|
|
correctionMessage: Try choosing a different name for the typedef.
|
|
hasPublishedDocs: true
|
|
caseBlockNotTerminated:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
caseExpressionTypeImplementsEquals:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type of the switch case expression
|
|
problemMessage: "The switch case expression type '#type' can't override the '==' operator."
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
caseExpressionTypeIsNotSwitchExpressionSubtype:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type caseExpressionType: the type of the case expression
|
|
Type scrutineeType: the type of the switch expression
|
|
problemMessage: "The switch case expression type '#caseExpressionType' must be a subtype of the switch expression type '#scrutineeType'."
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
castToNonType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the type
|
|
problemMessage: "The name '#name' 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 '#name'."
|
|
hasPublishedDocs: true
|
|
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;
|
|
```
|
|
classUsedAsMixin:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the class being used as a mixin
|
|
problemMessage: "The class '#name' can't be used as a mixin because it's neither a mixin class nor 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 {}
|
|
```
|
|
classUsedAsMixinDeclaresGenerativeConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class being used as a mixin
|
|
problemMessage: "The class '#className' can't be used as a mixin because it declares a generative constructor."
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class is used as a mixin and
|
|
the mixed-in class defines a generative constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces the diagnostic because class `A`
|
|
defines a generative constructor and is used as a mixin:
|
|
|
|
```dart
|
|
//@dart=2.19
|
|
class A {
|
|
A();
|
|
}
|
|
|
|
class B with [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If it's possible to convert the class to a mixin, then do so:
|
|
|
|
```dart
|
|
mixin A {
|
|
}
|
|
|
|
class B with A {}
|
|
```
|
|
|
|
If the class can't be a mixin and it's possible to remove the constructor,
|
|
then do so:
|
|
|
|
```dart
|
|
//@dart=2.19
|
|
class A {
|
|
}
|
|
|
|
class B with A {}
|
|
```
|
|
|
|
If the class can't be a mixin and you can't remove the constructor, then
|
|
try extending or implementing the class rather than mixing it in:
|
|
|
|
```dart
|
|
class A {
|
|
A();
|
|
}
|
|
|
|
class B extends A {}
|
|
```
|
|
|
|
classInstantiationAccessToInstanceMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the member
|
|
sharedName: classInstantiationAccessToMember
|
|
problemMessage: "The instance member '#name' can't be accessed on a class instantiation."
|
|
correctionMessage: Try changing the member name to the name of a constructor.
|
|
hasPublishedDocs: false
|
|
classInstantiationAccessToUnknownMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class
|
|
String memberName: the name of the member
|
|
sharedName: classInstantiationAccessToMember
|
|
problemMessage: "The class '#className' doesn't have a constructor named '#memberName'."
|
|
correctionMessage: "Try invoking a different constructor, or defining a constructor named '#memberName'."
|
|
hasPublishedDocs: false
|
|
classInstantiationAccessToStaticMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the member
|
|
sharedName: classInstantiationAccessToMember
|
|
problemMessage: "The static member '#name' 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
|
|
nonConstGenerativeEnumConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
%language=3.10
|
|
enum E {
|
|
e;
|
|
|
|
[!E!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the `const` keyword before the constructor:
|
|
|
|
```dart
|
|
enum E {
|
|
e;
|
|
|
|
const E();
|
|
}
|
|
```
|
|
nonConstantListElementFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: collectionElementFromDeferredLibrary
|
|
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
|
|
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];
|
|
```
|
|
nonConstantMapKeyFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: collectionElementFromDeferredLibrary
|
|
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
|
|
nonConstantMapValueFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: collectionElementFromDeferredLibrary
|
|
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
|
|
nonConstantRecordFieldFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
patternConstantFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Constant values from a deferred library can't be used in patterns.
|
|
correctionMessage: Try removing the keyword 'deferred' from the import.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
recordLiteralOnePositionalNoTrailingCommaByType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: recordLiteralOnePositionalNoTrailingComma
|
|
problemMessage: "A record literal with exactly one positional field requires a trailing comma."
|
|
correctionMessage: Try adding a trailing comma.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This is similar to
|
|
ParserErrorCode.recordLiteralOnePositionalNoTrailingComma, but
|
|
it is reported at type analysis time, based on a type
|
|
incompatibility, rather than at parse time.
|
|
setElementFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: collectionElementFromDeferredLibrary
|
|
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
|
|
concreteClassHasEnumSuperinterface:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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 {}
|
|
```
|
|
concreteClassWithAbstractMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the abstract method
|
|
String enclosingClass: the name of the enclosing class
|
|
problemMessage: "'#methodName' must have a method body because '#enclosingClass' isn't abstract."
|
|
correctionMessage: "Try making '#enclosingClass' abstract, or adding a body to '#methodName'."
|
|
hasPublishedDocs: true
|
|
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();
|
|
}
|
|
```
|
|
conflictingConstructorAndStaticField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the constructor and field
|
|
sharedName: conflictingConstructorAndStaticMember
|
|
problemMessage: "'#name' 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
|
|
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.
|
|
conflictingConstructorAndStaticGetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the constructor and getter
|
|
sharedName: conflictingConstructorAndStaticMember
|
|
problemMessage: "'#name' 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
|
|
conflictingConstructorAndStaticMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the constructor
|
|
sharedName: conflictingConstructorAndStaticMember
|
|
problemMessage: "'#name' 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
|
|
conflictingConstructorAndStaticSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the constructor and setter
|
|
sharedName: conflictingConstructorAndStaticMember
|
|
problemMessage: "'#name' 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
|
|
conflictingFieldAndMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class defining the conflicting field
|
|
String fieldName: the name of the conflicting field
|
|
String conflictingClassName: the name of the class defining the method with which the field conflicts
|
|
problemMessage: "Class '#className' can't define field '#fieldName' and have method '#conflictingClassName.#fieldName' 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`.
|
|
conflictingGenericInterfaces:
|
|
type: compileTimeError
|
|
parameters:
|
|
String kind: the name of the kind of the element implementing the conflicting interface
|
|
String element: the name of the element implementing the conflicting interface
|
|
String type1: the first conflicting type
|
|
String type2: the second conflicting type
|
|
problemMessage: "The #kind '#element' can't implement both '#type1' and '#type2' because the type arguments are different."
|
|
hasPublishedDocs: true
|
|
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 {}
|
|
```
|
|
conflictingInheritedMethodAndSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String enclosingElementKind: the name of the enclosing element kind - class, extension type, etc
|
|
String enclosingElementName: the name of the enclosing element
|
|
String memberName: the name of the conflicting method / setter
|
|
problemMessage: "The #enclosingElementKind '#enclosingElementName' can't inherit both a method and a setter named '#memberName'."
|
|
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`.
|
|
conflictingMethodAndField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class defining the conflicting method
|
|
String methodName: the name of the conflicting method
|
|
String conflictingClassName: the name of the class defining the field with which the method conflicts
|
|
problemMessage: "Class '#className' can't define method '#methodName' and have field '#conflictingClassName.#methodName' 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`.
|
|
conflictingStaticAndInstance:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class defining the conflicting member
|
|
String memberName: the name of the conflicting static member
|
|
String conflictingClassName: the name of the class defining the field with which the method conflicts
|
|
problemMessage: "Class '#className' can't define static member '#memberName' and have instance member '#conflictingClassName.#memberName' 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`.
|
|
conflictingTypeVariableAndClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndContainer
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and the class in which the type parameter is defined."
|
|
correctionMessage: Try renaming either the type parameter or the class.
|
|
hasPublishedDocs: true
|
|
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> {}
|
|
```
|
|
conflictingTypeVariableAndEnum:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndContainer
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and the enum in which the type parameter is defined."
|
|
correctionMessage: Try renaming either the type parameter or the enum.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndExtension:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndContainer
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and the extension in which the type parameter is defined."
|
|
correctionMessage: Try renaming either the type parameter or the extension.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndExtensionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndContainer
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and the extension type in which the type parameter is defined."
|
|
correctionMessage: Try renaming either the type parameter or the extension.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndMixin:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndContainer
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and the mixin in which the type parameter is defined."
|
|
correctionMessage: Try renaming either the type parameter or the mixin.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndMemberClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndMember
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and a member in this class."
|
|
correctionMessage: Try renaming either the type parameter or the member.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
```
|
|
conflictingTypeVariableAndMemberMixin:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndMember
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and a member in this mixin."
|
|
correctionMessage: Try renaming either the type parameter or the member.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndMemberEnum:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndMember
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and a member in this enum."
|
|
correctionMessage: Try renaming either the type parameter or the member.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndMemberExtension:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndMember
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and a member in this extension."
|
|
correctionMessage: Try renaming either the type parameter or the member.
|
|
hasPublishedDocs: true
|
|
conflictingTypeVariableAndMemberExtensionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
sharedName: conflictingTypeVariableAndMember
|
|
problemMessage: "'#typeParameterName' can't be used to name both a type parameter and a member in this extension type."
|
|
correctionMessage: Try renaming either the type parameter or the member.
|
|
hasPublishedDocs: true
|
|
constConstructorFieldTypeMismatch:
|
|
type: compileTimeError
|
|
parameters:
|
|
String valueType: the type of the runtime value of the argument
|
|
String fieldName: the name of the field
|
|
String fieldType: the type of the field
|
|
problemMessage: "In a const constructor, a value of type '#valueType' can't be assigned to the field '#fieldName', which has type '#fieldType'."
|
|
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.
|
|
constConstructorConstantFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: collectionElementFromDeferredLibrary
|
|
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
|
|
constConstructorParamTypeMismatch:
|
|
type: compileTimeError
|
|
parameters:
|
|
String valueType: the type of the runtime value of the argument
|
|
String parameterType: the static type of the parameter
|
|
problemMessage: "A value of type '#valueType' can't be assigned to a parameter of type '#parameterType' in a const constructor."
|
|
correctionMessage: "Try using a subtype, or removing the keyword 'const'."
|
|
hasPublishedDocs: true
|
|
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');
|
|
}
|
|
```
|
|
constConstructorThrowsException:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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.
|
|
constConstructorWithFieldInitializedByNonConst:
|
|
type: compileTimeError
|
|
parameters:
|
|
String fieldName: the name of the field
|
|
problemMessage: "Can't define the 'const' constructor because the field '#fieldName' 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
|
|
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();
|
|
}
|
|
```
|
|
constConstructorWithMixinWithField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String fieldName: the name of the instance field.
|
|
problemMessage: "This constructor can't be declared 'const' because a mixin adds the instance field: #fieldName."
|
|
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.
|
|
constConstructorWithMixinWithFields:
|
|
type: compileTimeError
|
|
parameters:
|
|
String fieldNames: the names of the instance fields.
|
|
sharedName: constConstructorWithMixinWithField
|
|
problemMessage: "This constructor can't be declared 'const' because the mixins add the instance fields: #fieldNames."
|
|
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.
|
|
constConstructorWithNonConstSuper:
|
|
type: compileTimeError
|
|
parameters:
|
|
String superclassName: the name of the superclass
|
|
problemMessage: "A constant constructor can't call a non-constant super constructor of '#superclassName'."
|
|
correctionMessage: "Try calling a constant constructor in the superclass, or removing the keyword 'const' from the constructor."
|
|
hasPublishedDocs: true
|
|
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();
|
|
}
|
|
```
|
|
constConstructorWithNonFinalField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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);
|
|
}
|
|
```
|
|
constDeferredClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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();
|
|
```
|
|
constEvalAssertionFailure:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The assertion in this constant expression failed."
|
|
hasPublishedDocs: false
|
|
constEvalAssertionFailureWithMessage:
|
|
type: compileTimeError
|
|
parameters:
|
|
String message: the message of the assertion
|
|
problemMessage: "An assertion failed with message '#message'."
|
|
hasPublishedDocs: false
|
|
constEvalExtensionMethod:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension methods can't be used in constant expressions."
|
|
hasPublishedDocs: false
|
|
constEvalExtensionTypeMethod:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension type methods can't be used in constant expressions."
|
|
hasPublishedDocs: false
|
|
constEvalForElement:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant expressions don't support 'for' elements."
|
|
correctionMessage: "Try replacing the 'for' element with a spread, or removing 'const'."
|
|
hasPublishedDocs: false
|
|
constEvalPropertyAccess:
|
|
type: compileTimeError
|
|
parameters:
|
|
String propertyName: the name of the property being accessed
|
|
String type: the type with the property being accessed
|
|
problemMessage: "The property '#propertyName' can't be accessed on the type '#type' in a constant expression."
|
|
hasPublishedDocs: false
|
|
constEvalMethodInvocation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Methods can't be invoked in constant expressions."
|
|
hasPublishedDocs: false
|
|
constEvalThrowsException:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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.
|
|
constEvalThrowsIdbze:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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.
|
|
constEvalTypeBool:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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".
|
|
constEvalTypeBoolInt:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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".
|
|
constEvalTypeBoolNumString:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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".
|
|
constEvalPrimitiveEquality:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "In constant expressions, operands of the equality operator must have primitive equality."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
|
|
for text about "An expression of the form e1 == e2".
|
|
constEvalTypeInt:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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".
|
|
constEvalTypeNum:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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".
|
|
constEvalTypeNumString:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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".
|
|
constEvalTypeString:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "In constant expressions, operands of this operator must be of type 'String'."
|
|
hasPublishedDocs: false
|
|
constEvalTypeType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "In constant expressions, operands of this operator must be of type 'Type'."
|
|
hasPublishedDocs: false
|
|
constInitializedWithNonConstantValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Const variables must be initialized with a constant value.
|
|
correctionMessage: Try changing the initializer to be a constant expression.
|
|
hasPublishedDocs: true
|
|
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;
|
|
```
|
|
constInitializedWithNonConstantValueFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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;
|
|
```
|
|
constInstanceField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Only static fields can be declared as const.
|
|
correctionMessage: "Try declaring the field as final, or adding the keyword 'static'."
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
```
|
|
constMapKeyNotPrimitiveEquality:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type keyType: the type of the entry's key
|
|
problemMessage: "The type of a key in a constant map can't override the '==' operator, or 'hashCode', but the class '#keyType' does."
|
|
correctionMessage: "Try using a different value for the key, or removing the keyword 'const' from the map."
|
|
hasPublishedDocs: true
|
|
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};
|
|
```
|
|
constNotInitialized:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the uninitialized final variable
|
|
problemMessage: "The constant '#name' must be initialized."
|
|
correctionMessage: Try adding an initialization to the declaration.
|
|
hasPublishedDocs: true
|
|
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';
|
|
```
|
|
constSetElementNotPrimitiveEquality:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type of the element
|
|
problemMessage: "An element in a constant set can't override the '==' operator, or 'hashCode', but the type '#type' 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
|
|
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()};
|
|
```
|
|
constSpreadExpectedListOrSet:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A list or a set is expected in this spread.
|
|
hasPublishedDocs: true
|
|
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];
|
|
```
|
|
constSpreadExpectedMap:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A map is expected in this spread.
|
|
hasPublishedDocs: true
|
|
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};
|
|
```
|
|
constTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Type parameters can't be used in a constant expression."
|
|
correctionMessage: Try replacing the type parameter with a different type.
|
|
hasPublishedDocs: false
|
|
constantVariableAugmentation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
problemMessage: "Variable augmentations can't be const."
|
|
correctionMessage: "Try replacing 'const' with 'final'."
|
|
hasPublishedDocs: false
|
|
constWithNonConst:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The constructor being called isn't a const constructor."
|
|
correctionMessage: "Try removing 'const' from the constructor invocation."
|
|
hasPublishedDocs: true
|
|
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();
|
|
```
|
|
constWithNonConstantArgument:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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);
|
|
```
|
|
constWithTypeParameters:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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>();
|
|
```
|
|
constWithTypeParametersConstructorTearoff:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: constWithTypeParameters
|
|
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
|
|
constWithTypeParametersFunctionTearoff:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: constWithTypeParameters
|
|
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
|
|
constWithUndefinedConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the type
|
|
String constructorName: the name of the requested constant constructor
|
|
problemMessage: "The class '#className' doesn't have a constant constructor '#constructorName'."
|
|
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>.
|
|
constWithUndefinedConstructorDefault:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the type
|
|
problemMessage: "The class '#className' 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>.
|
|
constantPatternWithNonConstantExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The expression of a constant pattern must be a valid constant.
|
|
correctionMessage: Try making the expression a valid constant.
|
|
hasPublishedDocs: true
|
|
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) {}
|
|
}
|
|
```
|
|
continueLabelInvalid:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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.
|
|
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.
|
|
couldNotInfer:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
String detailText: detail text explaining why the type could not be inferred
|
|
problemMessage: "Couldn't infer type parameter '#typeParameterName'.#detailText"
|
|
hasPublishedDocs: false
|
|
newWithNonType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the non-type element
|
|
sharedName: creationWithNonType
|
|
problemMessage: "The name '#name' isn't a class."
|
|
correctionMessage: Try correcting the name to match an existing class.
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
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();
|
|
}
|
|
```
|
|
constWithNonType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the non-type element
|
|
sharedName: creationWithNonType
|
|
problemMessage: "The name '#name' isn't a class."
|
|
correctionMessage: Try correcting the name to match an existing class.
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
constructorAlreadyComplete:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: declarationAlreadyComplete
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation can't provide a body, initializers, or initializing formal or super formal parameters because the constructor is already complete."
|
|
correctionMessage: "Try removing the body, initializers, or initializing formal or super formal parameters from the augmentation, or removing the body, initializers, or initializing formal or super formal parameters from the preceding declaration."
|
|
hasPublishedDocs: false
|
|
defaultListConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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
|
|
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);
|
|
```
|
|
defaultValueInRedirectingFactoryConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Default values aren't allowed in factory constructors that redirect to another constructor."
|
|
correctionMessage: Try removing the default value.
|
|
hasPublishedDocs: true
|
|
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]) {}
|
|
}
|
|
```
|
|
defaultValueOnRequiredParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Required named parameters can't have a default value."
|
|
correctionMessage: "Try removing either the default value or the 'required' modifier."
|
|
hasPublishedDocs: true
|
|
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'}) {}
|
|
```
|
|
deferredImportOfExtension:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Deferred library imports must hide all extension declarations.
|
|
correctionMessage: Try adding either a show combinator listing the names you need to reference or a hide combinator listing all of the extension declarations.
|
|
hasPublishedDocs: true
|
|
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();
|
|
}
|
|
```
|
|
definitelyUnassignedLateLocalVariable:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable that is invalid
|
|
problemMessage: "The late local variable '#name' is definitely unassigned at this point."
|
|
correctionMessage: Ensure that it is assigned on necessary execution paths.
|
|
hasPublishedDocs: true
|
|
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);
|
|
}
|
|
```
|
|
disallowedTypeInstantiationExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
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.
|
|
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);
|
|
}
|
|
```
|
|
duplicateConstructorName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the duplicate entity
|
|
sharedName: duplicateConstructor
|
|
problemMessage: "The constructor with name '#name' is already defined."
|
|
correctionMessage: Try renaming one of the constructors.
|
|
hasPublishedDocs: true
|
|
dotShorthandMissingContext:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A dot shorthand can't be used where there is no context type."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a dot shorthand is used where
|
|
there is no context type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because there is no context
|
|
type for the expression `.a`:
|
|
|
|
```dart
|
|
void f() {
|
|
var e = [!.a!];
|
|
print(e);
|
|
}
|
|
|
|
enum E {a, b}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to use a dot shorthand, then add a context type, which in this
|
|
example means adding the explicit type `E` to the local variable:
|
|
|
|
```dart
|
|
void f() {
|
|
E e = .a;
|
|
print(e);
|
|
}
|
|
|
|
enum E {a, b}
|
|
```
|
|
|
|
If you don't want to add a context type, then specify the name of the
|
|
type containing the member being referenced, which in this case is `E`:
|
|
|
|
```dart
|
|
void f() {
|
|
var e = E.a;
|
|
print(e);
|
|
}
|
|
|
|
enum E {a, b}
|
|
```
|
|
dotShorthandUndefinedGetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String getterName: the name of the static getter
|
|
String typeName: the name of the enclosing type where the getter is being looked for
|
|
sharedName: dotShorthandUndefinedMember
|
|
problemMessage: "The static getter '#getterName' isn't defined for the context type '#typeName'."
|
|
correctionMessage: "Try correcting the name to the name of an existing static getter, or defining a getter or field named '#getterName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a dot shorthand is used to
|
|
reference a member, but that member doesn't exist.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum `E` doesn't
|
|
define a static member named `c`:
|
|
|
|
```dart
|
|
void f() {
|
|
E e = .[!c!];
|
|
print(e);
|
|
}
|
|
|
|
enum E {a, b}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name is correct, then define a member with that name in the context
|
|
type, which in this case is the enum `E`:
|
|
|
|
```dart
|
|
void f() {
|
|
E e = .c;
|
|
print(e);
|
|
}
|
|
|
|
enum E {a, b, c}
|
|
```
|
|
|
|
If the name is not correct, then replace the name with the name of an
|
|
existing member from the context type, which in this case is the enum `E`:
|
|
|
|
```dart
|
|
void f() {
|
|
E e = .b;
|
|
print(e);
|
|
}
|
|
|
|
enum E {a, b}
|
|
```
|
|
dotShorthandUndefinedInvocation:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the static method or constructor
|
|
String contextType: the name of the enclosing type where the method or constructor is being looked for
|
|
sharedName: dotShorthandUndefinedMember
|
|
problemMessage: "The static method or constructor '#name' isn't defined for the context type '#contextType'."
|
|
correctionMessage: "Try correcting the name to the name of an existing static method or constructor, or defining a static method or constructor named '#name'."
|
|
hasPublishedDocs: true
|
|
duplicateConstructorDefault:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: duplicateConstructor
|
|
problemMessage: The unnamed constructor is already defined.
|
|
correctionMessage: Try giving one of the constructors a name.
|
|
hasPublishedDocs: true
|
|
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();
|
|
}
|
|
```
|
|
duplicateDefinition:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the duplicate entity
|
|
problemMessage: "The name '#name' is already defined."
|
|
correctionMessage: Try renaming one of the declarations.
|
|
hasPublishedDocs: true
|
|
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;
|
|
```
|
|
duplicateFieldName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the duplicated name
|
|
problemMessage: The field name '#name' is already used in this record.
|
|
correctionMessage: Try renaming the field.
|
|
hasPublishedDocs: true
|
|
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);
|
|
```
|
|
duplicateFieldFormalParameter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the field
|
|
problemMessage: "The field '#name' can't be initialized by multiple parameters in the same constructor."
|
|
correctionMessage: Try removing one of the parameters, or using different fields.
|
|
hasPublishedDocs: true
|
|
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) {}
|
|
}
|
|
```
|
|
functionAlreadyComplete:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: declarationAlreadyComplete
|
|
experiment: augmentations
|
|
problemMessage: "The augmentation can't provide a body because the function or member is already complete."
|
|
correctionMessage: "Try removing the body from the augmentation, or removing the body from the preceding declaration."
|
|
hasPublishedDocs: false
|
|
functionNotCompleteAfterAugmentations:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the function, method, getter, or setter
|
|
experiment: augmentations
|
|
problemMessage: "The function or member '#name' must have a body after all augmentations are applied."
|
|
correctionMessage: "Try adding a body to the introductory declaration, or providing an augmentation with a body."
|
|
hasPublishedDocs: false
|
|
inducedGetterWithoutBody:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable inducing the getter
|
|
experiment: augmentations
|
|
problemMessage: "The getter induced by '#name' must have a body."
|
|
correctionMessage: "Try removing 'abstract' and adding an initializer."
|
|
hasPublishedDocs: false
|
|
inducedSetterWithoutBody:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable inducing the setter
|
|
experiment: augmentations
|
|
problemMessage: "The setter induced by '#name' must have a body."
|
|
correctionMessage: "Try removing 'abstract' and adding an initializer."
|
|
hasPublishedDocs: false
|
|
inducedGetterNotCompleteAfterAugmentations:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable inducing the getter
|
|
experiment: augmentations
|
|
problemMessage: "The getter induced by '#name' must have a body after all augmentations are applied."
|
|
correctionMessage: "Try adding an initializer or providing an augmentation with a getter body."
|
|
hasPublishedDocs: false
|
|
inducedSetterNotCompleteAfterAugmentations:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable inducing the setter
|
|
experiment: augmentations
|
|
problemMessage: "The setter induced by '#name' must have a body after all augmentations are applied."
|
|
correctionMessage: "Try adding an initializer or providing an augmentation with a setter body."
|
|
hasPublishedDocs: false
|
|
factoryNotCompleteAfterAugmentations:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the factory constructor
|
|
experiment: augmentations
|
|
problemMessage: "The factory constructor '#name' must have a body or redirection after all augmentations are applied."
|
|
correctionMessage: "Try adding a body or redirection to the introductory declaration, or providing an augmentation with a body or redirection."
|
|
hasPublishedDocs: false
|
|
defaultValueAlreadySpecifiedInAugmentationChain:
|
|
type: compileTimeError
|
|
parameters: none
|
|
experiment: augmentations
|
|
problemMessage: "The default value for this optional parameter was already specified in the augmentation chain."
|
|
correctionMessage: "Try removing all but one of the default values."
|
|
hasPublishedDocs: false
|
|
duplicateNamedArgument:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the parameter that was duplicated
|
|
problemMessage: "The argument for the named parameter '#name' 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
|
|
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}) {}
|
|
}
|
|
```
|
|
duplicatePart:
|
|
type: compileTimeError
|
|
parameters:
|
|
Uri uri: the URI of the duplicate part
|
|
problemMessage: "The library already contains a part with the URI '#uri'."
|
|
correctionMessage: Try removing all except one of the duplicated part directives.
|
|
hasPublishedDocs: true
|
|
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 'test.dart';
|
|
```
|
|
|
|
The following code produces this diagnostic because the file `part.dart` is
|
|
included multiple times:
|
|
|
|
```dart
|
|
part 'part.dart';
|
|
part [!'part.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all except the first of the duplicated part directives:
|
|
|
|
```dart
|
|
part 'part.dart';
|
|
```
|
|
duplicatePatternAssignmentVariable:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable
|
|
problemMessage: The variable '#name' is already assigned in this pattern.
|
|
correctionMessage: Try renaming the variable.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
```
|
|
duplicatePatternField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the field
|
|
problemMessage: The field '#name' is already matched in this pattern.
|
|
correctionMessage: Try removing the duplicate field.
|
|
hasPublishedDocs: true
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
duplicateRestElementInPattern:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: At most one rest element is allowed in a list or map pattern.
|
|
correctionMessage: Try removing the duplicate rest element.
|
|
hasPublishedDocs: true
|
|
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, ...]) {}
|
|
}
|
|
```
|
|
duplicateVariablePattern:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable
|
|
problemMessage: The variable '#name' is already defined in this pattern.
|
|
correctionMessage: Try renaming the variable.
|
|
hasPublishedDocs: true
|
|
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);
|
|
}
|
|
}
|
|
```
|
|
emptyMapPattern:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A map pattern must have at least one entry.
|
|
correctionMessage: Try replacing it with an object pattern 'Map()'.
|
|
hasPublishedDocs: true
|
|
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()) {}
|
|
}
|
|
```
|
|
|
|
If the pattern should only match an empty map, then check the length
|
|
in the pattern:
|
|
|
|
```dart
|
|
void f(Map<int, String> x) {
|
|
if (x case Map(isEmpty: true)) {}
|
|
}
|
|
```
|
|
enumConstantInvokesFactoryConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "An enum value can't invoke a factory constructor."
|
|
correctionMessage: Try using a generative constructor.
|
|
hasPublishedDocs: false
|
|
enumConstantSameNameAsEnclosing:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The name of the enum value can't be the same as the enum's name."
|
|
correctionMessage: Try renaming the constant.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enum value has the same name
|
|
as the enum in which it's declared.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum value `E` has
|
|
the same name as the enclosing enum `E`:
|
|
|
|
```dart
|
|
enum E {
|
|
[!E!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name of the enum is correct, then rename the constant:
|
|
|
|
```dart
|
|
enum E {
|
|
e
|
|
}
|
|
```
|
|
|
|
If the name of the constant is correct, then rename the enum:
|
|
|
|
```dart
|
|
enum F {
|
|
E
|
|
}
|
|
```
|
|
enumConstantWithNonConstConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
removedIn: "3.3"
|
|
problemMessage: The invoked constructor isn't a 'const' constructor.
|
|
correctionMessage: Try invoking a 'const' generative constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enum value is being created
|
|
using either a factory constructor or a generative constructor that isn't
|
|
marked as being `const`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum value `e` is
|
|
being initialized by a factory constructor:
|
|
|
|
```dart
|
|
enum E {
|
|
[!e!]();
|
|
|
|
factory E() => e;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use a generative constructor marked as `const`:
|
|
|
|
```dart
|
|
enum E {
|
|
e._();
|
|
|
|
factory E() => e;
|
|
|
|
const E._();
|
|
}
|
|
```
|
|
enumInstantiatedToBoundsIsNotWellBounded:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The result of instantiating the enum to bounds is not well-bounded.
|
|
correctionMessage: Try using different bounds for type parameters.
|
|
hasPublishedDocs: false
|
|
enumMixinWithInstanceVariable:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Mixins applied to enums can't have instance variables.
|
|
correctionMessage: Try replacing the instance variables with getters.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin that's applied to an
|
|
enum declares one or more instance variables. This isn't allowed because
|
|
the enum values are constant, and there isn't any way for the constructor
|
|
in the enum to initialize any of the mixin's fields.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the mixin `M` defines
|
|
the instance field `x`:
|
|
|
|
```dart
|
|
mixin M {
|
|
int x = 0;
|
|
}
|
|
|
|
enum E with [!M!] {
|
|
a
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to apply the mixin, then change all instance fields into
|
|
getter and setter pairs and implement them in the enum if necessary:
|
|
|
|
```dart
|
|
mixin M {
|
|
int get x => 0;
|
|
}
|
|
|
|
enum E with M {
|
|
a
|
|
}
|
|
```
|
|
|
|
If you don't need to apply the mixin, then remove it:
|
|
|
|
```dart
|
|
enum E {
|
|
a
|
|
}
|
|
```
|
|
enumWithAbstractMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the abstract method
|
|
String enclosingClass: the name of the enclosing enum
|
|
problemMessage: "'#methodName' must have a method body because '#enclosingClass' is an enum."
|
|
correctionMessage: "Try adding a body to '#methodName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member of an enum is found
|
|
that doesn't have a concrete implementation. Enums aren't allowed to
|
|
contain abstract members.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `m` is an abstract
|
|
method and `E` is an enum:
|
|
|
|
```dart
|
|
enum E {
|
|
e;
|
|
|
|
[!void m();!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Provide an implementation for the member:
|
|
|
|
```dart
|
|
enum E {
|
|
e;
|
|
|
|
void m() {}
|
|
}
|
|
```
|
|
enumWithNameValues:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The name 'values' is not a valid name for an enum.
|
|
correctionMessage: Try using a different name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enum is declared to have the
|
|
name `values`. This isn't allowed because the enum has an implicit static
|
|
field named `values`, and the two would collide.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because there's an enum
|
|
declaration that has the name `values`:
|
|
|
|
```dart
|
|
enum [!values!] {
|
|
c
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename the enum to something other than `values`.
|
|
enumWithoutConstants:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The enum must have at least one enum constant.
|
|
correctionMessage: Try declaring an enum constant.
|
|
hasPublishedDocs: false
|
|
equalElementsInConstSet:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Two elements in a constant set literal can't be equal."
|
|
correctionMessage: Change or remove the duplicate element.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when two elements in a constant set
|
|
literal have the same value. The set can only contain each value once,
|
|
which means that one of the values is unnecessary.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the string `'a'` is
|
|
specified twice:
|
|
|
|
```dart
|
|
const Set<String> set = {'a', [!'a'!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove one of the duplicate values:
|
|
|
|
```dart
|
|
const Set<String> set = {'a'};
|
|
```
|
|
|
|
Note that literal sets preserve the order of their elements, so the choice
|
|
of which element to remove might affect the order in which elements are
|
|
returned by an iterator.
|
|
equalKeysInConstMap:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Two keys in a constant map literal can't be equal."
|
|
correctionMessage: Change or remove the duplicate key.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key in a constant map is the
|
|
same as a previous key in the same map. If two keys are the same, then the
|
|
second value would overwrite the first value, which makes having both pairs
|
|
pointless.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the key `1` is used
|
|
twice:
|
|
|
|
```dart
|
|
const map = <int, String>{1: 'a', 2: 'b', [!1!]: 'c', 4: 'd'};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If both entries should be included in the map, then change one of the keys
|
|
to be different:
|
|
|
|
```dart
|
|
const map = <int, String>{1: 'a', 2: 'b', 3: 'c', 4: 'd'};
|
|
```
|
|
|
|
If only one of the entries is needed, then remove the one that isn't
|
|
needed:
|
|
|
|
```dart
|
|
const map = <int, String>{1: 'a', 2: 'b', 4: 'd'};
|
|
```
|
|
|
|
Note that literal maps preserve the order of their entries, so the choice
|
|
of which entry to remove might affect the order in which keys and values
|
|
are returned by an iterator.
|
|
equalKeysInMapPattern:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Two keys in a map pattern can't be equal.
|
|
correctionMessage: Change or remove the duplicate key.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a map pattern contains more
|
|
than one key with the same name. The same key can't be matched twice.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the key `'a'` appears
|
|
twice:
|
|
|
|
```dart
|
|
void f(Map<String, int> x) {
|
|
if (x case {'a': 1, [!'a'!]: 2}) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you are trying to match two different keys, then change one of the keys
|
|
in the pattern:
|
|
|
|
```dart
|
|
void f(Map<String, int> x) {
|
|
if (x case {'a': 1, 'b': 2}) {}
|
|
}
|
|
```
|
|
|
|
If you are trying to match the same key, but allow any one of multiple
|
|
patterns to match, the use a logical-or pattern:
|
|
|
|
```dart
|
|
void f(Map<String, int> x) {
|
|
if (x case {'a': 1 || 2}) {}
|
|
}
|
|
```
|
|
expectedOneListPatternTypeArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
int count: the number of provided type arguments
|
|
problemMessage: "List patterns require one type argument or none, but #count found."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a list pattern has more than
|
|
one type argument. List patterns can have either zero type arguments or
|
|
one type argument, but can't have more than one.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the list pattern
|
|
(`[0]`) has two type arguments:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
if (x case [!<int, int>!][0]) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the type arguments:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
if (x case <int>[0]) {}
|
|
}
|
|
```
|
|
expectedOneListTypeArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
int count: the number of provided type arguments
|
|
problemMessage: "List literals require one type argument or none, but #count found."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a list literal has more than one
|
|
type argument.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the list literal has
|
|
two type arguments when it can have at most one:
|
|
|
|
```dart
|
|
var l = [!<int, int>!][];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all except one of the type arguments:
|
|
|
|
```dart
|
|
var l = <int>[];
|
|
```
|
|
expectedOneSetTypeArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
int count: the number of provided type arguments
|
|
problemMessage: "Set literals require one type argument or none, but #count were found."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a set literal has more than one
|
|
type argument.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the set literal has
|
|
three type arguments when it can have at most one:
|
|
|
|
```dart
|
|
var s = [!<int, String, int>!]{0, 'a', 1};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all except one of the type arguments:
|
|
|
|
```dart
|
|
var s = <int>{0, 1};
|
|
```
|
|
expectedTwoMapTypeArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
int count: the number of provided type arguments
|
|
problemMessage: "Map literals require two type arguments or none, but #count found."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a map literal has either one or
|
|
more than two type arguments.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the map literal has
|
|
three type arguments when it can have either two or zero:
|
|
|
|
```dart
|
|
var m = [!<int, String, int>!]{};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all except two of the type arguments:
|
|
|
|
```dart
|
|
var m = <int, String>{};
|
|
```
|
|
expectedTwoMapPatternTypeArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
int count: the number of provided type arguments
|
|
problemMessage: "Map patterns require two type arguments or none, but #count found."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a map pattern has either one
|
|
type argument or more than two type arguments. Map patterns can have
|
|
either two type arguments or zero type arguments, but can't have any other
|
|
number.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the map pattern
|
|
(`<int>{}`) has one type argument:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
if (x case [!<int>!]{0: _}) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add or remove type arguments until there are two, or none:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
if (x case <int, int>{0: _}) {}
|
|
}
|
|
```
|
|
exportInternalLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uri: the URI pointing to a library
|
|
problemMessage: "The library '#uri' is internal and can't be exported."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds an export whose `dart:`
|
|
URI references an internal library.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `_interceptors` is an
|
|
internal library:
|
|
|
|
```dart
|
|
%ignore=uri_does_not_exist
|
|
[!export 'dart:_interceptors';!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the export directive.
|
|
exportLegacySymbol:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the name of a symbol defined in a legacy library
|
|
removedIn: "3.0"
|
|
problemMessage: "The symbol '#p0' is defined in a legacy library, and can't be re-exported from a library with null safety enabled."
|
|
correctionMessage: Try removing the export or migrating the legacy library.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library that was opted in to
|
|
null safety exports another library, and the exported library is opted out
|
|
of null safety.
|
|
|
|
#### Example
|
|
|
|
Given a library that is opted out of null safety:
|
|
|
|
```dart
|
|
%uri="lib/optedOut.dart"
|
|
// @dart = 2.8
|
|
String s;
|
|
```
|
|
|
|
The following code produces this diagnostic because it's exporting symbols
|
|
from an opted-out library:
|
|
|
|
```dart
|
|
export [!'optedOut.dart'!];
|
|
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're able to do so, migrate the exported library so that it doesn't
|
|
need to opt out:
|
|
|
|
```dart
|
|
String? s;
|
|
```
|
|
|
|
If you can't migrate the library, then remove the export:
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
|
|
If the exported library (the one that is opted out) itself exports an
|
|
opted-in library, then it's valid for your library to indirectly export the
|
|
symbols from the opted-in library. You can do so by adding a hide
|
|
combinator to the export directive in your library that hides all of the
|
|
names declared in the opted-out library.
|
|
exportOfNonLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uri: the URI pointing to a non-library declaration
|
|
problemMessage: "The exported library '#uri' can't have a part-of directive."
|
|
correctionMessage: Try exporting the library that the part is a part of.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an export directive references a
|
|
part rather than a library.
|
|
|
|
#### 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
|
|
a part, and only libraries can be exported:
|
|
|
|
```dart
|
|
library lib;
|
|
|
|
export [!'part.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Either remove the export directive, or change the URI to be the URI of the
|
|
library containing the part.
|
|
expressionInMap:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Expressions can't be used in a map literal."
|
|
correctionMessage: Try removing the expression or converting it to be a map entry.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the analyzer finds an
|
|
expression, rather than a map entry, in what appears to be a map literal.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
var map = <String, int>{'a': 0, 'b': 1, [!'c'!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the expression is intended to compute either a key or a value in an
|
|
entry, fix the issue by replacing the expression with the key or the value.
|
|
For example:
|
|
|
|
```dart
|
|
var map = <String, int>{'a': 0, 'b': 1, 'c': 2};
|
|
```
|
|
extendsNonClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Classes can only extend other classes.
|
|
correctionMessage: Try specifying a different superclass, or removing the extends clause.
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `extends` clause contains a
|
|
name that is declared to be something other than a class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is declared to be a
|
|
function:
|
|
|
|
```dart
|
|
void f() {}
|
|
|
|
class C extends [!f!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want the class to extend a class other than `Object`, then replace
|
|
the name in the `extends` clause with the name of that class:
|
|
|
|
```dart
|
|
void f() {}
|
|
|
|
class C extends B {}
|
|
|
|
class B {}
|
|
```
|
|
|
|
If you want the class to extend `Object`, then remove the `extends` clause:
|
|
|
|
```dart
|
|
void f() {}
|
|
|
|
class C {}
|
|
```
|
|
extensionAsExpression:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the extension
|
|
problemMessage: "Extension '#name' can't be used as an expression."
|
|
correctionMessage: Try replacing it with a valid expression.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the name of an extension is used
|
|
in an expression other than in an extension override or to qualify an
|
|
access to a static member of the extension. Because classes define a type,
|
|
the name of a class can be used to refer to the instance of `Type`
|
|
representing the type of the class. Extensions, on the other hand, don't
|
|
define a type and can't be used as a type literal.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `E` is an extension:
|
|
|
|
```dart
|
|
extension E on int {
|
|
static String m() => '';
|
|
}
|
|
|
|
var x = [!E!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the name of the extension with a name that can be referenced, such
|
|
as a static member defined on the extension:
|
|
|
|
```dart
|
|
extension E on int {
|
|
static String m() => '';
|
|
}
|
|
|
|
var x = E.m();
|
|
```
|
|
extensionConflictingStaticAndInstance:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the conflicting static member
|
|
problemMessage: "An extension can't define static member '#name' and an instance member with the same name."
|
|
correctionMessage: "Try renaming the member to a name that doesn't conflict."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension declaration
|
|
contains both an instance member and a static member that have the same
|
|
name. The instance member and the static member can't have the same name
|
|
because it's unclear which member is being referenced by an unqualified use
|
|
of the name within the body of the extension.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `a` is being
|
|
used for two different members:
|
|
|
|
```dart
|
|
extension E on Object {
|
|
int get a => 0;
|
|
static int [!a!]() => 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename or remove one of the members:
|
|
|
|
```dart
|
|
extension E on Object {
|
|
int get a => 0;
|
|
static int b() => 0;
|
|
}
|
|
```
|
|
extensionDeclaresInstanceField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extensions can't declare instance fields."
|
|
correctionMessage: Try replacing the field with a getter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an instance field declaration is
|
|
found in an extension. It isn't valid to define an instance field because
|
|
extensions can only add behavior, not state.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `s` is an instance
|
|
field:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String [!s!] = '';
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the value can be computed without storing it in a field, then try
|
|
using a getter or a method:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String get s => '';
|
|
}
|
|
```
|
|
|
|
If the value must be stored, but is the same for every instance,
|
|
try using a static field:
|
|
|
|
```dart
|
|
extension E on String {
|
|
static String s = '';
|
|
}
|
|
```
|
|
|
|
If each instance needs to have its own value stored, then try
|
|
using a getter and setter pair backed by a static `Expando`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
static final _s = Expando<String>();
|
|
|
|
String get s => _s[this] ?? '';
|
|
set s(String value) => _s[this] = value;
|
|
}
|
|
```
|
|
|
|
extensionDeclaresMemberOfObject:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extensions can't declare members with the same name as a member declared by 'Object'."
|
|
correctionMessage: Try specifying a different name for the member.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension declaration
|
|
declares a member with the same name as a member declared in the class
|
|
`Object`. Such a member can never be used because the member in `Object` is
|
|
always found first.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `toString` is defined
|
|
by `Object`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String [!toString!]() => this;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the member or rename it so that the name doesn't conflict with the
|
|
member in `Object`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String displayString() => this;
|
|
}
|
|
```
|
|
extensionOverrideAccessToStaticMember:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "An extension override can't be used to access a static member from an extension."
|
|
correctionMessage: Try using just the name of the extension.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is the
|
|
receiver of the invocation of a static member. Similar to static members in
|
|
classes, the static members of an extension should be accessed using the
|
|
name of the extension, not an extension override.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `m` is static:
|
|
|
|
```dart
|
|
extension E on String {
|
|
static void m() {}
|
|
}
|
|
|
|
void f() {
|
|
E('').[!m!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the extension override with the name of the extension:
|
|
|
|
```dart
|
|
extension E on String {
|
|
static void m() {}
|
|
}
|
|
|
|
void f() {
|
|
E.m();
|
|
}
|
|
```
|
|
extensionOverrideArgumentNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type argumentType: the type of the argument
|
|
Type extendedType: the extended type
|
|
problemMessage: "The type of the argument to the extension override '#argumentType' isn't assignable to the extended type '#extendedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the argument to an extension
|
|
override isn't assignable to the type being extended by the extension.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `3` isn't a `String`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
void method() {}
|
|
}
|
|
|
|
void f() {
|
|
E([!3!]).method();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're using the correct extension, then update the argument to have the
|
|
correct type:
|
|
|
|
```dart
|
|
extension E on String {
|
|
void method() {}
|
|
}
|
|
|
|
void f() {
|
|
E(3.toString()).method();
|
|
}
|
|
```
|
|
|
|
If there's a different extension that's valid for the type of the argument,
|
|
then either replace the name of the extension or unwrap the argument so
|
|
that the correct extension is found.
|
|
extensionOverrideWithoutAccess:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: An extension override can only be used to access instance members.
|
|
correctionMessage: Consider adding an access to an instance member.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is found
|
|
that isn't being used to access one of the members of the extension. The
|
|
extension override syntax doesn't have any runtime semantics; it only
|
|
controls which member is selected at compile time.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `E(i)` isn't an
|
|
expression:
|
|
|
|
```dart
|
|
extension E on int {
|
|
int get a => 0;
|
|
}
|
|
|
|
void f(int i) {
|
|
print([!E(i)!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to invoke one of the members of the extension, then add the
|
|
invocation:
|
|
|
|
```dart
|
|
extension E on int {
|
|
int get a => 0;
|
|
}
|
|
|
|
void f(int i) {
|
|
print(E(i).a);
|
|
}
|
|
```
|
|
|
|
If you don't want to invoke a member, then unwrap the argument:
|
|
|
|
```dart
|
|
extension E on int {
|
|
int get a => 0;
|
|
}
|
|
|
|
void f(int i) {
|
|
print(i);
|
|
}
|
|
```
|
|
extensionOverrideWithCascade:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension overrides have no value so they can't be used as the receiver of a cascade expression."
|
|
correctionMessage: "Try using '.' instead of '..'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is used as
|
|
the receiver of a cascade expression. The value of a cascade expression
|
|
`e..m` is the value of the receiver `e`, but extension overrides aren't
|
|
expressions and don't have a value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `E(3)` isn't an
|
|
expression:
|
|
|
|
```dart
|
|
extension E on int {
|
|
void m() {}
|
|
}
|
|
f() {
|
|
[!E!](3)..m();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use `.` rather than `..`:
|
|
|
|
```dart
|
|
extension E on int {
|
|
void m() {}
|
|
}
|
|
f() {
|
|
E(3).m();
|
|
}
|
|
```
|
|
|
|
If there are multiple cascaded accesses, you'll need to duplicate the
|
|
extension override for each one.
|
|
extensionTypeConstructorWithSuperFormalParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension type constructors can't declare super formal parameters."
|
|
correctionMessage: Try removing the super formal parameter declaration.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor in an extension
|
|
type has a super parameter. Super parameters aren't valid because
|
|
extension types don't have a superclass.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the named constructor
|
|
`n` contains a super parameter:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
E.n(this.i, [!super!].foo);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need the parameter, replace the super parameter with a normal
|
|
parameter:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
E.n(this.i, String foo);
|
|
}
|
|
```
|
|
|
|
If you don't need the parameter, remove the super parameter:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
E.n(this.i);
|
|
}
|
|
```
|
|
extensionTypeConstructorWithSuperInvocation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Extension type constructors can't include super initializers.
|
|
correctionMessage: Try removing the super constructor invocation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor in an extension
|
|
type includes an invocation of a super constructor in the initializer
|
|
list. Because extension types don't have a superclass, there's no
|
|
constructor to invoke.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor `E.n`
|
|
invokes a super constructor in its initializer list:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
E.n() : i = 0, [!super!].n();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the invocation of the super constructor:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
E.n() : i = 0;
|
|
}
|
|
```
|
|
extensionTypeDeclaresInstanceField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension types can't declare instance fields."
|
|
correctionMessage: Try replacing the field with a getter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a field declaration in
|
|
the body of an extension type declaration.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension type `E`
|
|
declares a field named `f`:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
final int [!f!] = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need the field, then remove it or replace it with a getter
|
|
and/or setter:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
int get f => 0;
|
|
}
|
|
```
|
|
|
|
If you need the field, then convert the extension type into a class:
|
|
|
|
```dart
|
|
class E {
|
|
final int i;
|
|
|
|
final int f = 0;
|
|
|
|
E(this.i);
|
|
}
|
|
```
|
|
extensionTypeDeclaresMemberOfObject:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension types can't declare members with the same name as a member declared by 'Object'."
|
|
correctionMessage: Try specifying a different name for the member.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of an extension type
|
|
declaration contains a member with the same name as one of the members
|
|
declared by `Object`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `Object`
|
|
already defines a member named `hashCode`:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
int get [!hashCode!] => 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need a member with the implemented semantics, then rename the
|
|
member:
|
|
|
|
```dart
|
|
extension type E(int i) {
|
|
int get myHashCode => 0;
|
|
}
|
|
```
|
|
|
|
If you don't need a member with the implemented semantics, then remove the
|
|
member:
|
|
|
|
```dart
|
|
extension type E(int i) {}
|
|
```
|
|
extensionTypeImplementsDisallowedType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the disallowed type
|
|
problemMessage: "Extension types can't implement '#type'."
|
|
correctionMessage: Try specifying a different type, or remove the type from the list.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type implements a
|
|
type that it isn't allowed to implement.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because extension types can't
|
|
implement the type `dynamic`:
|
|
|
|
```dart
|
|
extension type A(int i) implements [!dynamic!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the disallowed type from the implements clause:
|
|
|
|
```dart
|
|
extension type A(int i) {}
|
|
```
|
|
extensionTypeImplementsItself:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The extension type can't implement itself."
|
|
correctionMessage: Try removing the superinterface that references this extension type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type implements
|
|
itself, either directly or indirectly.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension type `A`
|
|
directly implements itself:
|
|
|
|
```dart
|
|
extension type [!A!](int i) implements A {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the extension type `A`
|
|
indirectly implements itself (through `B`):
|
|
|
|
```dart
|
|
extension type [!A!](int i) implements B {}
|
|
|
|
extension type [!B!](int i) implements A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Break the cycle by removing a type from the implements clause of at least
|
|
one of the types involved in the cycle:
|
|
|
|
```dart
|
|
extension type A(int i) implements B {}
|
|
|
|
extension type B(int i) {}
|
|
```
|
|
extensionTypeImplementsNotSupertype:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the implemented not extension type
|
|
Type representationType: the ultimate representation type
|
|
problemMessage: "'#type' is not a supertype of '#representationType', the representation type."
|
|
correctionMessage: Try specifying a different type, or remove the type from the list.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type implements a
|
|
type that isn't a supertype of the representation type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension type `A`
|
|
implements `String`, but `String` isn't a supertype of the representation
|
|
type `int`:
|
|
|
|
```dart
|
|
extension type A(int i) implements [!String!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the representation type is correct, then remove or replace the type in
|
|
the implements clause:
|
|
|
|
```dart
|
|
extension type A(int i) {}
|
|
```
|
|
|
|
If the representation type isn't correct, then replace it with the correct
|
|
type:
|
|
|
|
```dart
|
|
extension type A(String s) implements String {}
|
|
```
|
|
extensionTypeImplementsRepresentationNotSupertype:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type implementedRepresentationType: the representation type of the implemented extension type
|
|
String implementedExtensionTypeName: the name of the implemented extension type
|
|
Type representationType: the representation type of the this extension type
|
|
String extensionTypeName: the name of the this extension type
|
|
problemMessage: "'#implementedRepresentationType', the representation type of '#implementedExtensionTypeName', is not a supertype of '#representationType', the representation type of '#extensionTypeName'."
|
|
correctionMessage: Try specifying a different type, or remove the type from the list.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type implements
|
|
another extension type, and the representation type of the implemented
|
|
extension type isn't a subtype of the representation type of the implementing
|
|
extension type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension type `B`
|
|
implements `A`, but the representation type of `A` (`num`) isn't a
|
|
subtype of the representation type of `B` (`String`):
|
|
|
|
```dart
|
|
extension type A(num i) {}
|
|
|
|
extension type B(String s) implements [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Either change the representation types of the two extension types so that
|
|
the representation type of the implemented type is a supertype of the
|
|
representation type of the implementing type:
|
|
|
|
```dart
|
|
extension type A(num i) {}
|
|
|
|
extension type B(int n) implements A {}
|
|
```
|
|
|
|
Or remove the implemented type from the implements clause:
|
|
|
|
```dart
|
|
extension type A(num i) {}
|
|
|
|
extension type B(String s) {}
|
|
```
|
|
extensionTypeInheritedMemberConflict:
|
|
type: compileTimeError
|
|
parameters:
|
|
String extensionTypeName: the name of the extension type
|
|
String memberName: the name of the conflicting member
|
|
problemMessage: "The extension type '#extensionTypeName' has more than one distinct member named '#memberName' from implemented types."
|
|
correctionMessage: Try redeclaring the corresponding member in this extension type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type implements
|
|
two or more other types, and at least two of those types declare a member
|
|
with the same name.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension type `C`
|
|
implements both `A` and `B`, and both declare a member named `m`:
|
|
|
|
```dart
|
|
class A {
|
|
void m() {}
|
|
}
|
|
|
|
extension type B(A a) {
|
|
void m() {}
|
|
}
|
|
|
|
extension type [!C!](A a) implements A, B {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the extension type doesn't need to implement all of the listed types,
|
|
then remove all but one of the types introducing the conflicting members:
|
|
|
|
```dart
|
|
class A {
|
|
void m() {}
|
|
}
|
|
|
|
extension type B(A a) {
|
|
void m() {}
|
|
}
|
|
|
|
extension type C(A a) implements A {}
|
|
```
|
|
|
|
If the extension type needs to implement all of the listed types but you
|
|
can rename the members in those types, then give the conflicting members
|
|
unique names:
|
|
|
|
```dart
|
|
class A {
|
|
void m() {}
|
|
}
|
|
|
|
extension type B(A a) {
|
|
void n() {}
|
|
}
|
|
|
|
extension type C(A a) implements A, B {}
|
|
```
|
|
extensionTypeRepresentationDependsOnItself:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The extension type representation can't depend on itself."
|
|
correctionMessage: Try specifying a different type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type has a
|
|
representation type that depends on the extension type itself, either
|
|
directly or indirectly.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the representation
|
|
type of the extension type `A` depends on `A` directly:
|
|
|
|
```dart
|
|
extension type [!A!](A a) {}
|
|
```
|
|
|
|
The following two code examples produce this diagnostic because the
|
|
representation type of the extension type `A` depends on `A`
|
|
indirectly through the extension type `B`:
|
|
|
|
```dart
|
|
extension type [!A!](B b) {}
|
|
|
|
extension type [!B!](A a) {}
|
|
```
|
|
|
|
```dart
|
|
extension type [!A!](List<B> b) {}
|
|
|
|
extension type [!B!](List<A> a) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the dependency by choosing a different representation type for at
|
|
least one of the types in the cycle:
|
|
|
|
```dart
|
|
extension type A(String s) {}
|
|
```
|
|
extensionTypeRepresentationTypeBottom:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The representation type can't be a bottom type."
|
|
correctionMessage: Try specifying a different type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the representation type of an
|
|
extension type is the [bottom type][] `Never`. The type `Never` can't be
|
|
the representation type of an extension type because there are no values
|
|
that can be extended.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the representation
|
|
type of the extension type `E` is `Never`:
|
|
|
|
```dart
|
|
extension type E([!Never!] n) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the extension type with a different type:
|
|
|
|
```dart
|
|
extension type E(String s) {}
|
|
```
|
|
extensionTypeWithAbstractMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the abstract method
|
|
String extensionTypeName: the name of the enclosing extension type
|
|
problemMessage: "'#methodName' must have a method body because '#extensionTypeName' is an extension type."
|
|
correctionMessage: "Try adding a body to '#methodName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension type declares an
|
|
abstract member. Because extension type member references are resolved
|
|
statically, an abstract member in an extension type could never be
|
|
executed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `m` in the
|
|
extension type `E` is abstract:
|
|
|
|
```dart
|
|
%language=3.5
|
|
extension type E(String s) {
|
|
[!void m();!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the member is intended to be executable, then provide an implementation
|
|
of the member:
|
|
|
|
```dart
|
|
extension type E(String s) {
|
|
void m() {}
|
|
}
|
|
```
|
|
|
|
If the member isn't intended to be executable, then remove it:
|
|
|
|
```dart
|
|
extension type E(String s) {}
|
|
```
|
|
externalFieldConstructorInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: externalWithInitializer
|
|
problemMessage: External fields can't have initializers.
|
|
correctionMessage: "Try removing the field initializer or the 'external' keyword from the field declaration."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field or variable marked with
|
|
the keyword `external` has an initializer, or when an external field is
|
|
initialized in a constructor.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the external field `x`
|
|
is assigned a value in an initializer:
|
|
|
|
```dart
|
|
class C {
|
|
external int x;
|
|
C() : [!x!] = 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the external field `x`
|
|
has an initializer:
|
|
|
|
```dart
|
|
class C {
|
|
external final int [!x!] = 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the external top level
|
|
variable `x` has an initializer:
|
|
|
|
```dart
|
|
external final int [!x!] = 0;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the initializer:
|
|
|
|
```dart
|
|
class C {
|
|
external final int x;
|
|
}
|
|
```
|
|
externalFieldInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: externalWithInitializer
|
|
problemMessage: External fields can't have initializers.
|
|
correctionMessage: "Try removing the initializer or the 'external' keyword."
|
|
hasPublishedDocs: true
|
|
externalVariableInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: externalWithInitializer
|
|
problemMessage: External variables can't have initializers.
|
|
correctionMessage: "Try removing the initializer or the 'external' keyword."
|
|
hasPublishedDocs: true
|
|
extraPositionalArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
int expected: the maximum number of positional arguments
|
|
int found: the actual number of positional arguments given
|
|
problemMessage: "Too many positional arguments: #expected expected, but #found found."
|
|
correctionMessage: Try removing the extra arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function invocation
|
|
has more positional arguments than the method or function allows.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` defines 2
|
|
parameters but is invoked with 3 arguments:
|
|
|
|
```dart
|
|
void f(int a, int b) {}
|
|
void g() {
|
|
f(1, 2, [!3!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the arguments that don't correspond to parameters:
|
|
|
|
```dart
|
|
void f(int a, int b) {}
|
|
void g() {
|
|
f(1, 2);
|
|
}
|
|
```
|
|
extraPositionalArgumentsCouldBeNamed:
|
|
type: compileTimeError
|
|
parameters:
|
|
int expected: the maximum number of positional arguments
|
|
int found: the actual number of positional arguments given
|
|
problemMessage: "Too many positional arguments: #expected expected, but #found found."
|
|
correctionMessage: Try removing the extra positional arguments, or specifying the name for named arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function invocation
|
|
has more positional arguments than the method or function allows, but the
|
|
method or function defines named parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` defines 2
|
|
positional parameters but has a named parameter that could be used for the
|
|
third argument:
|
|
|
|
```dart
|
|
void f(int a, int b, {int? c}) {}
|
|
void g() {
|
|
f(1, 2, [!3!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If some of the arguments should be values for named parameters, then add
|
|
the names before the arguments:
|
|
|
|
```dart
|
|
void f(int a, int b, {int? c}) {}
|
|
void g() {
|
|
f(1, 2, c: 3);
|
|
}
|
|
```
|
|
|
|
Otherwise, remove the arguments that don't correspond to positional
|
|
parameters:
|
|
|
|
```dart
|
|
void f(int a, int b, {int? c}) {}
|
|
void g() {
|
|
f(1, 2);
|
|
}
|
|
```
|
|
fieldInitializedByMultipleInitializers:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the field being initialized multiple times
|
|
problemMessage: "The field '#name' can't be initialized twice in the same constructor."
|
|
correctionMessage: Try removing one of the initializations.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the initializer list of a
|
|
constructor initializes a field more than once. There is no value to allow
|
|
both initializers because only the last value is preserved.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `f` is being
|
|
initialized twice:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C() : f = 0, [!f!] = 1;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove one of the initializers:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C() : f = 0;
|
|
}
|
|
```
|
|
fieldInitializedInInitializerAndDeclaration:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Fields can't be initialized in the constructor if they are final and were already initialized at their declaration."
|
|
correctionMessage: Try removing one of the initializations.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a final field is initialized in
|
|
both the declaration of the field and in an initializer in a constructor.
|
|
Final fields can only be assigned once, so it can't be initialized in both
|
|
places.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is :
|
|
|
|
```dart
|
|
class C {
|
|
final int f = 0;
|
|
C() : [!f!] = 1;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the initialization doesn't depend on any values passed to the
|
|
constructor, and if all of the constructors need to initialize the field to
|
|
the same value, then remove the initializer from the constructor:
|
|
|
|
```dart
|
|
class C {
|
|
final int f = 0;
|
|
C();
|
|
}
|
|
```
|
|
|
|
If the initialization depends on a value passed to the constructor, or if
|
|
different constructors need to initialize the field differently, then
|
|
remove the initializer in the field's declaration:
|
|
|
|
```dart
|
|
class C {
|
|
final int f;
|
|
C() : f = 1;
|
|
}
|
|
```
|
|
fieldInitializedInParameterAndInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Fields can't be initialized in both the parameter list and the initializers."
|
|
correctionMessage: Try removing one of the initializations.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field is initialized in both
|
|
the parameter list and in the initializer list of a constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `f` is
|
|
initialized both by an initializing formal parameter and in the
|
|
initializer list:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f) : [!f!] = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field should be initialized by the parameter, then remove the
|
|
initialization in the initializer list:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f);
|
|
}
|
|
```
|
|
|
|
If the field should be initialized in the initializer list and the
|
|
parameter isn't needed, then remove the parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C() : f = 0;
|
|
}
|
|
```
|
|
|
|
If the field should be initialized in the initializer list and the
|
|
parameter is needed, then make it a normal parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(int g) : f = g * 2;
|
|
}
|
|
```
|
|
fieldInitializerFactoryConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Initializing formal parameters can't be used in factory constructors."
|
|
correctionMessage: Try using a normal parameter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a factory constructor has an
|
|
initializing formal parameter. Factory constructors can't assign values to
|
|
fields because no instance is created; hence, there is no field to assign.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the factory constructor
|
|
uses an initializing formal parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int? f;
|
|
|
|
factory C([!this.f!]) => throw 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the initializing formal parameter with a normal parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int? f;
|
|
|
|
factory C(int f) => throw 0;
|
|
}
|
|
```
|
|
fieldInitializerNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type initializerExpressionType: the name of the type of the initializer expression
|
|
Type fieldType: the name of the type of the field
|
|
problemMessage: "The initializer type '#initializerExpressionType' can't be assigned to the field type '#fieldType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the initializer list of a
|
|
constructor initializes a field to a value that isn't assignable to the
|
|
field.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `0` has the type `int`,
|
|
and an `int` can't be assigned to a field of type `String`:
|
|
|
|
```dart
|
|
class C {
|
|
String s;
|
|
|
|
C() : s = [!0!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the field is correct, then change the value assigned to it
|
|
so that the value has a valid type:
|
|
|
|
```dart
|
|
class C {
|
|
String s;
|
|
|
|
C() : s = '0';
|
|
}
|
|
```
|
|
|
|
If the type of the value is correct, then change the type of the field to
|
|
allow the assignment:
|
|
|
|
```dart
|
|
class C {
|
|
int s;
|
|
|
|
C() : s = 0;
|
|
}
|
|
```
|
|
constFieldInitializerNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type initializerExpressionType: the name of the type of the initializer expression
|
|
Type fieldType: the name of the type of the field
|
|
sharedName: fieldInitializerNotAssignable
|
|
problemMessage: "The initializer type '#initializerExpressionType' can't be assigned to the field type '#fieldType' in a const constructor."
|
|
correctionMessage: "Try using a subtype, or removing the 'const' keyword"
|
|
hasPublishedDocs: true
|
|
fieldInitializerRedirectingConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The redirecting constructor can't have a field initializer."
|
|
correctionMessage: Try initializing the field in the constructor being redirected to.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a redirecting constructor
|
|
initializes a field in the object. This isn't allowed because the instance
|
|
that has the field hasn't been created at the point at which it should be
|
|
initialized.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the constructor
|
|
`C.zero`, which redirects to the constructor `C`, has an initializing
|
|
formal parameter that initializes the field `f`:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f);
|
|
|
|
C.zero([!this.f!]) : this(f);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the constructor
|
|
`C.zero`, which redirects to the constructor `C`, has an initializer that
|
|
initializes the field `f`:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f);
|
|
|
|
C.zero() : [!f = 0!], this(1);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the initialization is done by an initializing formal parameter, then
|
|
use a normal parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f);
|
|
|
|
C.zero(int f) : this(f);
|
|
}
|
|
```
|
|
|
|
If the initialization is done in an initializer, then remove the
|
|
initializer:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f);
|
|
|
|
C.zero() : this(0);
|
|
}
|
|
```
|
|
fieldInitializingFormalNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type formalParameterType: the name of the type of the field formal parameter
|
|
Type fieldType: the name of the type of the field
|
|
problemMessage: "The parameter type '#formalParameterType' is incompatible with the field type '#fieldType'."
|
|
correctionMessage: "Try changing or removing the parameter's type, or changing the field's type."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of an initializing
|
|
formal parameter isn't assignable to the type of the field being
|
|
initialized.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the initializing
|
|
formal parameter has the type `String`, but the type of the field is
|
|
`int`. The parameter must have a type that is a subtype of the field's
|
|
type.
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C([!String this.f!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the field is incorrect, then change the type of the field to
|
|
match the type of the parameter, and consider removing the type from the
|
|
parameter:
|
|
|
|
```dart
|
|
class C {
|
|
String f;
|
|
|
|
C(this.f);
|
|
}
|
|
```
|
|
|
|
If the type of the parameter is incorrect, then remove the type of the
|
|
parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(this.f);
|
|
}
|
|
```
|
|
|
|
If the types of both the field and the parameter are correct, then use an
|
|
initializer rather than an initializing formal parameter to convert the
|
|
parameter value into a value of the correct type:
|
|
|
|
```dart
|
|
class C {
|
|
int f;
|
|
|
|
C(String s) : f = int.parse(s);
|
|
}
|
|
```
|
|
finalClassExtendedOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the final class being extended.
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The class '#name' can't be extended outside of its library because it's a final class."
|
|
hasPublishedDocs: true
|
|
finalClassImplementedOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the final class being implemented.
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The class '#name' can't be implemented outside of its library because it's a final class."
|
|
hasPublishedDocs: true
|
|
finalClassUsedAsMixinConstraintOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the final class being used as a mixin superclass constraint.
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The class '#name' can't be used as a mixin superclass constraint outside of its library because it's a final class."
|
|
hasPublishedDocs: true
|
|
finalInitializedInDeclarationAndConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the field in question
|
|
problemMessage: "'#name' is final and was given a value when it was declared, so it can't be set to a new value."
|
|
correctionMessage: Try removing one of the initializations.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a final field is initialized
|
|
twice: once where it's declared and once by a constructor's parameter.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `f` is
|
|
initialized twice:
|
|
|
|
```dart
|
|
class C {
|
|
final int f = 0;
|
|
|
|
C(this.[!f!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field should have the same value for all instances, then remove the
|
|
initialization in the parameter list:
|
|
|
|
```dart
|
|
class C {
|
|
final int f = 0;
|
|
|
|
C();
|
|
}
|
|
```
|
|
|
|
If the field can have different values in different instances, then remove
|
|
the initialization in the declaration:
|
|
|
|
```dart
|
|
class C {
|
|
final int f;
|
|
|
|
C(this.f);
|
|
}
|
|
```
|
|
finalNotInitialized:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the uninitialized final variable
|
|
problemMessage: "The final variable '#name' must be initialized."
|
|
correctionMessage: Try initializing the variable.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a final field or variable isn't
|
|
initialized.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` doesn't have an
|
|
initializer:
|
|
|
|
```dart
|
|
final [!x!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
For variables and static fields, you can add an initializer:
|
|
|
|
```dart
|
|
final x = 0;
|
|
```
|
|
|
|
For instance fields, you can add an initializer as shown in the previous
|
|
example, or you can initialize the field in every constructor. You can
|
|
initialize the field by using an initializing formal parameter:
|
|
|
|
```dart
|
|
class C {
|
|
final int x;
|
|
C(this.x);
|
|
}
|
|
```
|
|
|
|
You can also initialize the field by using an initializer in the
|
|
constructor:
|
|
|
|
```dart
|
|
class C {
|
|
final int x;
|
|
C(int y) : x = y * 2;
|
|
}
|
|
```
|
|
finalNotInitializedConstructor1:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the uninitialized final variable
|
|
sharedName: finalNotInitializedConstructor
|
|
problemMessage: "All final variables must be initialized, but '#name' isn't."
|
|
correctionMessage: Try adding an initializer for the field.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class defines one or more
|
|
final instance fields without initializers and has at least one constructor
|
|
that doesn't initialize those fields. All final instance fields must be
|
|
initialized when the instance is created, either by the field's initializer
|
|
or by the constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
class C {
|
|
final String value;
|
|
|
|
[!C!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the value should be passed in to the constructor directly, then use an
|
|
initializing formal parameter to initialize the field `value`:
|
|
|
|
```dart
|
|
class C {
|
|
final String value;
|
|
|
|
C(this.value);
|
|
}
|
|
```
|
|
|
|
If the value should be computed indirectly from a value provided by the
|
|
caller, then add a parameter and include an initializer:
|
|
|
|
```dart
|
|
class C {
|
|
final String value;
|
|
|
|
C(Object o) : value = o.toString();
|
|
}
|
|
```
|
|
|
|
If the value of the field doesn't depend on values that can be passed to
|
|
the constructor, then add an initializer for the field as part of the field
|
|
declaration:
|
|
|
|
```dart
|
|
class C {
|
|
final String value = '';
|
|
|
|
C();
|
|
}
|
|
```
|
|
|
|
If the value of the field doesn't depend on values that can be passed to
|
|
the constructor but different constructors need to initialize it to
|
|
different values, then add an initializer for the field in the initializer
|
|
list:
|
|
|
|
```dart
|
|
class C {
|
|
final String value;
|
|
|
|
C() : value = '';
|
|
|
|
C.named() : value = 'c';
|
|
}
|
|
```
|
|
|
|
However, if the value is the same for all instances, then consider using a
|
|
static field instead of an instance field:
|
|
|
|
```dart
|
|
class C {
|
|
static const String value = '';
|
|
|
|
C();
|
|
}
|
|
```
|
|
finalNotInitializedConstructor2:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name1: the name of the first uninitialized final variable
|
|
String name2: the name of the second uninitialized final variable
|
|
sharedName: finalNotInitializedConstructor
|
|
problemMessage: "All final variables must be initialized, but '#name1' and '#name2' aren't."
|
|
correctionMessage: Try adding initializers for the fields.
|
|
hasPublishedDocs: true
|
|
finalNotInitializedConstructor3Plus:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name1: the name of the first uninitialized final variable
|
|
String name2: the name of the second uninitialized final variable
|
|
int remainingCount: the number of additional not initialized variables that aren't listed
|
|
sharedName: finalNotInitializedConstructor
|
|
problemMessage: "All final variables must be initialized, but '#name1', '#name2', and #remainingCount others aren't."
|
|
correctionMessage: Try adding initializers for the fields.
|
|
hasPublishedDocs: true
|
|
forInOfInvalidElementType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type iterableType: the type of the iterable expression.
|
|
String expectedTypeName: the sequence type -- Iterable for `for` or Stream for `await for`.
|
|
Type loopVariableType: the loop variable type.
|
|
problemMessage: "The type '#iterableType' used in the 'for' loop must implement '#expectedTypeName' with a type argument that can be assigned to '#loopVariableType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `Iterable` or `Stream` in a
|
|
for-in loop has an element type that can't be assigned to the loop
|
|
variable.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `<String>[]` has an
|
|
element type of `String`, and `String` can't be assigned to the type of `e`
|
|
(`int`):
|
|
|
|
```dart
|
|
void f() {
|
|
for (int e in [!<String>[]!]) {
|
|
print(e);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the loop variable is correct, then update the type of the
|
|
iterable:
|
|
|
|
```dart
|
|
void f() {
|
|
for (int e in <int>[]) {
|
|
print(e);
|
|
}
|
|
}
|
|
```
|
|
|
|
If the type of the iterable is correct, then update the type of the loop
|
|
variable:
|
|
|
|
```dart
|
|
void f() {
|
|
for (String e in <String>[]) {
|
|
print(e);
|
|
}
|
|
}
|
|
```
|
|
forInOfInvalidType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type expressionType: the type of the iterable expression.
|
|
String expectedType: the sequence type -- Iterable for `for` or Stream for `await for`.
|
|
problemMessage: "The type '#expressionType' used in the 'for' loop must implement '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the expression following `in` in
|
|
a for-in loop has a type that isn't a subclass of `Iterable`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `m` is a `Map`, and
|
|
`Map` isn't a subclass of `Iterable`:
|
|
|
|
```dart
|
|
void f(Map<String, String> m) {
|
|
for (String s in [!m!]) {
|
|
print(s);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the expression with one that produces an iterable value:
|
|
|
|
```dart
|
|
void f(Map<String, String> m) {
|
|
for (String s in m.values) {
|
|
print(s);
|
|
}
|
|
}
|
|
```
|
|
forInWithConstVariable:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A for-in loop variable can't be a 'const'."
|
|
correctionMessage: "Try removing the 'const' modifier from the variable, or use a different variable."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the loop variable declared in a
|
|
for-in loop is declared to be a `const`. The variable can't be a `const`
|
|
because the value can't be computed at compile time.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the loop variable `x`
|
|
is declared to be a `const`:
|
|
|
|
```dart
|
|
void f() {
|
|
for ([!const!] x in [0, 1, 2]) {
|
|
print(x);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a type annotation, then remove the `const` modifier from the
|
|
declaration.
|
|
|
|
If there's no type, then replace the `const` modifier with `final`, `var`,
|
|
or a type annotation:
|
|
|
|
```dart
|
|
void f() {
|
|
for (final x in [0, 1, 2]) {
|
|
print(x);
|
|
}
|
|
}
|
|
```
|
|
genericFunctionTypeCannotBeBound:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Generic function types can't be used as type parameter bounds."
|
|
correctionMessage: Try making the free variable in the function type part of the larger declaration signature.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
It is a compile-time error if a generic function type is used as a bound
|
|
for a formal type parameter of a class or a function.
|
|
genericFunctionTypeCannotBeTypeArgument:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A generic function type can't be a type argument."
|
|
correctionMessage: "Try removing type parameters from the generic function type, or using 'dynamic' as the type argument here."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
It is a compile-time error if a generic function type is used as an actual
|
|
type argument.
|
|
genericMethodTypeInstantiationOnDynamic:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A method tear-off on a receiver whose type is 'dynamic' can't have type arguments."
|
|
correctionMessage: Specify the type of the receiver, or remove the type arguments from the method tear-off.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an instance method is being torn
|
|
off from a receiver whose type is `dynamic`, and the tear-off includes type
|
|
arguments. Because the analyzer can't know how many type parameters the
|
|
method has, or whether it has any type parameters, there's no way it can
|
|
validate that the type arguments are correct. As a result, the type
|
|
arguments aren't allowed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of `p` is
|
|
`dynamic` and the tear-off of `m` has type arguments:
|
|
|
|
```dart
|
|
void f(dynamic list) {
|
|
[!list.fold!]<int>;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can use a more specific type than `dynamic`, then change the type of
|
|
the receiver:
|
|
|
|
```dart
|
|
void f(List<Object> list) {
|
|
list.fold<int>;
|
|
}
|
|
```
|
|
|
|
If you can't use a more specific type, then remove the type arguments:
|
|
|
|
```dart
|
|
void f(dynamic list) {
|
|
list.cast;
|
|
}
|
|
```
|
|
getterNotAssignableSetterTypes:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the name of the getter
|
|
String p1: the type of the getter
|
|
String p2: the type of the setter
|
|
String p3: the name of the setter
|
|
removedIn: "3.4"
|
|
problemMessage: "The return type of getter '#p0' is '#p1' which isn't assignable to the type '#p2' of its setter '#p3'."
|
|
correctionMessage: Try changing the types so that they are compatible.
|
|
hasPublishedDocs: false
|
|
getterNotSubtypeSetterTypes:
|
|
type: compileTimeError
|
|
parameters:
|
|
String getterName: the name of the getter
|
|
Type getterType: the type of the getter
|
|
Type setterType: the type of the setter
|
|
String setterName: the name of the setter
|
|
problemMessage: "The return type of getter '#getterName' is '#getterType' which isn't a subtype of the type '#setterType' of its setter '#setterName'."
|
|
correctionMessage: Try changing the types so that they are compatible.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the return type of a getter
|
|
isn't a subtype of the type of the parameter of a setter with the same
|
|
name.
|
|
|
|
The subtype relationship is a requirement whether the getter and setter are
|
|
in the same class or whether one of them is in a superclass of the other.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the return type of the
|
|
getter `x` is `num`, the parameter type of the setter `x` is `int`, and
|
|
`num` isn't a subtype of `int`:
|
|
|
|
```dart
|
|
// @dart = 3.8
|
|
class C {
|
|
num get [!x!] => 0;
|
|
|
|
set x(int y) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the getter is correct, then change the type of the setter:
|
|
|
|
```dart
|
|
class C {
|
|
num get x => 0;
|
|
|
|
set x(num y) {}
|
|
}
|
|
```
|
|
|
|
If the type of the setter is correct, then change the type of the getter:
|
|
|
|
```dart
|
|
class C {
|
|
int get x => 0;
|
|
|
|
set x(int y) {}
|
|
}
|
|
```
|
|
ifElementConditionFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant values from a deferred library can't be used as values in an if condition inside a const collection literal."
|
|
correctionMessage: Try making the deferred import non-deferred.
|
|
hasPublishedDocs: false
|
|
illegalAsyncGeneratorReturnType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Functions marked 'async*' must have a return type that is a supertype of 'Stream<T>' for some type 'T'."
|
|
correctionMessage: "Try fixing the return type of the function, or removing the modifier 'async*' from the function body."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of a function has the
|
|
`async*` modifier even though the return type of the function isn't either
|
|
`Stream` or a supertype of `Stream`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the body of the
|
|
function `f` has the 'async*' modifier even though the return type `int`
|
|
isn't a supertype of `Stream`:
|
|
|
|
```dart
|
|
[!int!] f() async* {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function should be asynchronous, then change the return type to be
|
|
either `Stream` or a supertype of `Stream`:
|
|
|
|
```dart
|
|
Stream<int> f() async* {}
|
|
```
|
|
|
|
If the function should be synchronous, then remove the `async*` modifier:
|
|
|
|
```dart
|
|
int f() => 0;
|
|
```
|
|
illegalAsyncReturnType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Functions marked 'async' must have a return type which is a supertype of 'Future'."
|
|
correctionMessage: "Try fixing the return type of the function, or removing the modifier 'async' from the function body."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of a function has the
|
|
`async` modifier even though the return type of the function isn't
|
|
assignable to `Future`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the body of the
|
|
function `f` has the `async` modifier even though the return type isn't
|
|
assignable to `Future`:
|
|
|
|
```dart
|
|
[!int!] f() async {
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function should be asynchronous, then change the return type to be
|
|
assignable to `Future`:
|
|
|
|
```dart
|
|
Future<int> f() async {
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
If the function should be synchronous, then remove the `async` modifier:
|
|
|
|
```dart
|
|
int f() => 0;
|
|
```
|
|
illegalEnumValuesDeclaration:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: illegalEnumValues
|
|
problemMessage: An instance member named 'values' can't be declared in a class that implements 'Enum'.
|
|
correctionMessage: Try using a different name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either a class that implements
|
|
`Enum` or a mixin with a superclass constraint of `Enum` has an instance
|
|
member named `values`.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the class `C`, which
|
|
implements `Enum`, declares an instance field named `values`:
|
|
|
|
```dart
|
|
abstract class C implements Enum {
|
|
int get [!values!] => 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `B`, which
|
|
implements `Enum`, inherits an instance method named `values` from `A`:
|
|
|
|
```dart
|
|
abstract class A {
|
|
int values() => 0;
|
|
}
|
|
|
|
abstract class [!B!] extends A implements Enum {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the name of the conflicting member:
|
|
|
|
```dart
|
|
abstract class C implements Enum {
|
|
int get value => 0;
|
|
}
|
|
```
|
|
illegalEnumValuesInheritance:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class that declares 'values'
|
|
sharedName: illegalEnumValues
|
|
problemMessage: An instance member named 'values' can't be inherited from '#className' in a class that implements 'Enum'.
|
|
correctionMessage: Try using a different name.
|
|
hasPublishedDocs: true
|
|
illegalLanguageVersionOverride:
|
|
type: compileTimeError
|
|
parameters:
|
|
String requiredVersion: the required language version
|
|
problemMessage: "The language version must be #requiredVersion."
|
|
correctionMessage: Try removing the language version override and migrating the code.
|
|
hasPublishedDocs: false
|
|
illegalConcreteEnumMemberDeclaration:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of member that cannot be declared
|
|
sharedName: illegalConcreteEnumMember
|
|
problemMessage: A concrete instance member named '#name' can't be declared in a class that implements 'Enum'.
|
|
correctionMessage: Try using a different name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either an enum declaration, a
|
|
class that implements `Enum`, or a mixin with a superclass constraint of
|
|
`Enum`, declares or inherits a concrete instance member named either
|
|
`index`, `hashCode`, or `==`.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the enum `E` declares
|
|
an instance getter named `index`:
|
|
|
|
```dart
|
|
enum E {
|
|
v;
|
|
|
|
int get [!index!] => 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `C`, which
|
|
implements `Enum`, declares an instance field named `hashCode`:
|
|
|
|
```dart
|
|
abstract class C implements Enum {
|
|
int [!hashCode!] = 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `C`, which
|
|
indirectly implements `Enum` through the class `A`, declares an instance
|
|
getter named `hashCode`:
|
|
|
|
```dart
|
|
abstract class A implements Enum {}
|
|
|
|
abstract class C implements A {
|
|
int get [!hashCode!] => 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the mixin `M`, which
|
|
has `Enum` in the `on` clause, declares an explicit operator named `==`:
|
|
|
|
```dart
|
|
mixin M on Enum {
|
|
bool operator [!==!](Object other) => false;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename the conflicting member:
|
|
|
|
```dart
|
|
enum E {
|
|
v;
|
|
|
|
int get getIndex => 0;
|
|
}
|
|
```
|
|
illegalConcreteEnumMemberInheritance:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of member that cannot be inherited
|
|
String className: the name of the class that declares the member
|
|
sharedName: illegalConcreteEnumMember
|
|
problemMessage: A concrete instance member named '#memberName' can't be inherited from '#className' in a class that implements 'Enum'.
|
|
correctionMessage: Try using a different name.
|
|
hasPublishedDocs: true
|
|
illegalSyncGeneratorReturnType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Functions marked 'sync*' must have a return type that is a supertype of 'Iterable<T>' for some type 'T'."
|
|
correctionMessage: "Try fixing the return type of the function, or removing the modifier 'sync*' from the function body."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of a function has the
|
|
`sync*` modifier even though the return type of the function isn't either
|
|
`Iterable` or a supertype of `Iterable`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the body of the
|
|
function `f` has the 'sync*' modifier even though the return type `int`
|
|
isn't a supertype of `Iterable`:
|
|
|
|
```dart
|
|
[!int!] f() sync* {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function should return an iterable, then change the return type to
|
|
be either `Iterable` or a supertype of `Iterable`:
|
|
|
|
```dart
|
|
Iterable<int> f() sync* {}
|
|
```
|
|
|
|
If the function should return a single value, then remove the `sync*`
|
|
modifier:
|
|
|
|
```dart
|
|
int f() => 0;
|
|
```
|
|
implementsNonClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Classes and mixins can only implement other classes and mixins.
|
|
correctionMessage: Try specifying a class or mixin, or remove the name from the list.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name used in the `implements`
|
|
clause of a class or mixin declaration is defined to be something other
|
|
than a class or mixin.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` is a variable
|
|
rather than a class or mixin:
|
|
|
|
```dart
|
|
var x;
|
|
class C implements [!x!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name is the name of an existing class or mixin that's already being
|
|
imported, then add a prefix to the import so that the local definition of
|
|
the name doesn't shadow the imported name.
|
|
|
|
If the name is the name of an existing class or mixin that isn't being
|
|
imported, then add an import, with a prefix, for the library in which it's
|
|
declared.
|
|
|
|
Otherwise, either replace the name in the `implements` clause with the name
|
|
of an existing class or mixin, or remove the name from the `implements`
|
|
clause.
|
|
implementsRepeated:
|
|
type: compileTimeError
|
|
parameters:
|
|
String interfaceName: the name of the interface that is implemented more than once
|
|
problemMessage: "'#interfaceName' can only be implemented once."
|
|
correctionMessage: Try removing all but one occurrence of the class name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a single class is specified more
|
|
than once in an `implements` clause.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A` is in the list
|
|
twice:
|
|
|
|
```dart
|
|
class A {}
|
|
class B implements A, [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all except one occurrence of the class name:
|
|
|
|
```dart
|
|
class A {}
|
|
class B implements A {}
|
|
```
|
|
implementsSuperClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
Element superElement: the name of the class that appears in both "extends" and "implements" clauses
|
|
problemMessage: "'#superElement' can't be used in both the 'extends' and 'implements' clauses."
|
|
correctionMessage: Try removing one of the occurrences.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class is listed in the
|
|
`extends` clause of a class declaration and also in either the
|
|
`implements` or `with` clause of the same declaration.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `A` is used
|
|
in both the `extends` and `implements` clauses for the class `B`:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B extends A implements [!A!] {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `A` is used
|
|
in both the `extends` and `with` clauses for the class `B`:
|
|
|
|
```dart
|
|
mixin class A {}
|
|
|
|
class B extends A with [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to inherit the implementation from the class, then remove the
|
|
class from the `implements` clause:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
```
|
|
|
|
If you don't want to inherit the implementation from the class, then remove
|
|
the `extends` clause:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B implements A {}
|
|
```
|
|
implementsSuperClassConstraint:
|
|
type: compileTimeError
|
|
parameters:
|
|
Element superElement: the class that appears in both the "on" and "implements" clauses
|
|
problemMessage: "'#superElement' can't be used in both the 'on' and 'implements' clauses."
|
|
correctionMessage: Try removing the type from the 'implements' clause.
|
|
hasPublishedDocs: false
|
|
implicitThisReferenceInInitializer:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the instance member
|
|
problemMessage: "The instance member '#memberName' can't be accessed in an initializer."
|
|
correctionMessage: Try replacing the reference to the instance member with a different expression
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds a reference to an
|
|
instance member in a constructor's initializer list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `defaultX` is an
|
|
instance member:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
|
|
C() : x = [!defaultX!];
|
|
|
|
int get defaultX => 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the member can be made static, then do so:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
|
|
C() : x = defaultX;
|
|
|
|
static int get defaultX => 0;
|
|
}
|
|
```
|
|
|
|
If not, then replace the reference in the initializer with a different
|
|
expression that doesn't use an instance member:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
|
|
C() : x = 0;
|
|
|
|
int get defaultX => 0;
|
|
}
|
|
```
|
|
implicitSuperInitializerMissingArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type superType: the name of the superclass
|
|
problemMessage: The implicitly invoked unnamed constructor from '#superType' has required parameters.
|
|
correctionMessage: Try adding an explicit super parameter with the required arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor implicitly
|
|
invokes the unnamed constructor from the superclass, the unnamed
|
|
constructor of the superclass has a required parameter, and there's no
|
|
super parameter corresponding to the required parameter.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the unnamed
|
|
constructor in the class `B` implicitly invokes the unnamed constructor in
|
|
the class `A`, but the constructor in `A` has a required positional
|
|
parameter named `x`:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
[!B!]();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the unnamed
|
|
constructor in the class `B` implicitly invokes the unnamed constructor in
|
|
the class `A`, but the constructor in `A` has a required named parameter
|
|
named `x`:
|
|
|
|
```dart
|
|
class A {
|
|
A({required int x});
|
|
}
|
|
|
|
class B extends A {
|
|
[!B!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can add a parameter to the constructor in the subclass, then add a
|
|
super parameter corresponding to the required parameter in the superclass'
|
|
constructor. The new parameter can either be required:
|
|
|
|
```dart
|
|
class A {
|
|
A({required int x});
|
|
}
|
|
|
|
class B extends A {
|
|
B({required super.x});
|
|
}
|
|
```
|
|
|
|
or it can be optional:
|
|
|
|
```dart
|
|
class A {
|
|
A({required int x});
|
|
}
|
|
|
|
class B extends A {
|
|
B({super.x = 0});
|
|
}
|
|
```
|
|
|
|
If you can't add a parameter to the constructor in the subclass, then add
|
|
an explicit super constructor invocation with the required argument:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super(0);
|
|
}
|
|
```
|
|
importInternalLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uri: the URI pointing to a library
|
|
problemMessage: "The library '#uri' is internal and can't be imported."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds an import whose `dart:`
|
|
URI references an internal library.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `_interceptors` is an
|
|
internal library:
|
|
|
|
```dart
|
|
%ignore=uri_does_not_exist
|
|
import [!'dart:_interceptors'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the import directive.
|
|
importOfNonLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uri: the URI pointing to a non-library declaration
|
|
problemMessage: "The imported library '#uri' can't have a part-of directive."
|
|
correctionMessage: Try importing the library that the part is a part of.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a [part file][] is imported
|
|
into a library.
|
|
|
|
#### Example
|
|
|
|
Given a [part file][] named `part.dart` containing the following:
|
|
|
|
```dart
|
|
%uri="lib/part.dart"
|
|
part of lib;
|
|
```
|
|
|
|
The following code produces this diagnostic because imported files can't
|
|
have a part-of directive:
|
|
|
|
```dart
|
|
library lib;
|
|
|
|
import [!'part.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Import the library that contains the [part file][] rather than the
|
|
[part file][] itself.
|
|
inconsistentCaseExpressionTypes:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the expression source code that is the unexpected type
|
|
String p1: the name of the expected type
|
|
removedIn: "3.4"
|
|
problemMessage: "Case expressions must have the same types, '#p0' isn't a '#p1'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
13.9 Switch: It is a compile-time error if values of the expressions
|
|
<i>e<sub>k</sub></i> are not instances of the same class <i>C</i>, for all
|
|
<i>1 <= k <= n</i>.
|
|
inconsistentInheritance:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the instance member with inconsistent inheritance.
|
|
String inheritedSignatures: the list of all inherited signatures for this member.
|
|
problemMessage: "Superinterfaces don't have a valid override for '#name': #inheritedSignatures."
|
|
correctionMessage: Try adding an explicit override that is consistent with all of the inherited members.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class inherits two or more
|
|
conflicting signatures for a member and doesn't provide an implementation
|
|
that satisfies all the inherited signatures.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `C` is inheriting the
|
|
declaration of `m` from `A`, and that implementation isn't consistent with
|
|
the signature of `m` that's inherited from `B`:
|
|
|
|
```dart
|
|
class A {
|
|
void m({int? a}) {}
|
|
}
|
|
|
|
class B {
|
|
void m({int? b}) {}
|
|
}
|
|
|
|
class [!C!] extends A implements B {
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an implementation of the method that satisfies all the inherited
|
|
signatures:
|
|
|
|
```dart
|
|
class A {
|
|
void m({int? a}) {}
|
|
}
|
|
|
|
class B {
|
|
void m({int? b}) {}
|
|
}
|
|
|
|
class C extends A implements B {
|
|
void m({int? a, int? b}) {}
|
|
}
|
|
```
|
|
inconsistentInheritanceGetterAndMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the instance member with inconsistent inheritance.
|
|
String getterInterface: the name of the superinterface that declares the name as a getter.
|
|
String methodInterface: the name of the superinterface that declares the name as a method.
|
|
problemMessage: "'#memberName' is inherited as a getter (from '#getterInterface') and also a method (from '#methodInterface')."
|
|
correctionMessage: Try adjusting the supertypes of this class to remove the inconsistency.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
11.1.1 Inheritance and Overriding. Let `I` be the implicit interface of a
|
|
class `C` declared in library `L`. `I` inherits all members of
|
|
`inherited(I, L)` and `I` overrides `m'` if `m' ∈ overrides(I, L)`. It is
|
|
a compile-time error if `m` is a method and `m'` is a getter, or if `m`
|
|
is a getter and `m'` is a method.
|
|
inconsistentLanguageVersionOverride:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Parts must have exactly the same language version override as the library.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a [part file][] has a language
|
|
version override comment that specifies a different language version than
|
|
the one being used for the library to which the part belongs.
|
|
|
|
#### Example
|
|
|
|
Given a [part file][] named `part.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/part.dart"
|
|
// @dart = 2.14
|
|
part of 'test.dart';
|
|
```
|
|
|
|
The following code produces this diagnostic because the parts of a library
|
|
must have the same language version as the defining compilation unit:
|
|
|
|
```dart
|
|
// @dart = 2.15
|
|
part [!'part.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the language version override from the [part file][], so that it
|
|
implicitly uses the same version as the defining compilation unit:
|
|
|
|
```dart
|
|
%uri="lib/part.dart"
|
|
part of 'test.dart';
|
|
```
|
|
|
|
If necessary, either adjust the language version override in the defining
|
|
compilation unit to be appropriate for the code in the part, or migrate
|
|
the code in the [part file][] to be consistent with the new language
|
|
version.
|
|
inconsistentPatternVariableLogicalOr:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the pattern variable
|
|
problemMessage: "The variable '#name' has a different type and/or finality in this branch of the logical-or pattern."
|
|
correctionMessage: Try declaring the variable pattern with the same type and finality in both branches.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a pattern variable that is
|
|
declared on all branches of a logical-or pattern doesn't have the same
|
|
type on every branch. It is also produced when the variable has a
|
|
different finality on different branches. A pattern variable declared on
|
|
multiple branches of a logical-or pattern is required to have the same
|
|
type and finality in each branch, so that the type and finality of the
|
|
variable can be known in code that's guarded by the logical-or pattern.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the variable `a` is
|
|
defined to be an `int` on one branch and a `double` on the other:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case (int a) || (double [!a!])) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the variable `a` is
|
|
`final` in the first branch and isn't `final` in the second branch:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case (final int a) || (int [!a!])) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the finality of the variable is different, decide whether it should be
|
|
`final` or not `final` and make the cases consistent:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case (int a) || (int a)) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
If the type of the variable is different and the type isn't critical to
|
|
the condition being matched, then ensure that the variable has the same
|
|
type on both branches:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case (num a) || (num a)) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
If the type of the variable is different and the type is critical to the
|
|
condition being matched, then consider breaking the condition into
|
|
multiple `if` statements or `case` clauses:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case int a) {
|
|
print(a);
|
|
} else if (x case double a) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
initializerForNonExistentField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String formalName: the name of the initializing formal that is not an instance variable in the immediately enclosing class
|
|
problemMessage: "'#formalName' isn't a field in the enclosing class."
|
|
correctionMessage: "Try correcting the name to match an existing field, or defining a field named '#formalName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor initializes a
|
|
field that isn't declared in the class containing the constructor.
|
|
Constructors can't initialize fields that aren't declared and fields that
|
|
are inherited from superclasses.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the initializer is
|
|
initializing `x`, but `x` isn't a field in the class:
|
|
|
|
```dart
|
|
class C {
|
|
int? y;
|
|
|
|
C() : [!x = 0!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a different field should be initialized, then change the name to the
|
|
name of the field:
|
|
|
|
```dart
|
|
class C {
|
|
int? y;
|
|
|
|
C() : y = 0;
|
|
}
|
|
```
|
|
|
|
If the field must be declared, then add a declaration:
|
|
|
|
```dart
|
|
class C {
|
|
int? x;
|
|
int? y;
|
|
|
|
C() : x = 0;
|
|
}
|
|
```
|
|
initializerForStaticField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String formalName: the name of the initializing formal that is a static variable in the immediately enclosing class
|
|
problemMessage: "'#formalName' is a static field in the enclosing class. Fields initialized in a constructor can't be static."
|
|
correctionMessage: Try removing the initialization.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a static field is initialized
|
|
in a constructor using either an initializing formal parameter or an
|
|
assignment in the initializer list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the static field `a`
|
|
is being initialized by the initializing formal parameter `this.a`:
|
|
|
|
```dart
|
|
class C {
|
|
static int? a;
|
|
C([!this!].a);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field should be an instance field, then remove the keyword `static`:
|
|
|
|
```dart
|
|
class C {
|
|
int? a;
|
|
C(this.a);
|
|
}
|
|
```
|
|
|
|
If you intended to initialize an instance field and typed the wrong name,
|
|
then correct the name of the field being initialized:
|
|
|
|
```dart
|
|
class C {
|
|
static int? a;
|
|
int? b;
|
|
C(this.b);
|
|
}
|
|
```
|
|
|
|
If you really want to initialize the static field, then move the
|
|
initialization into the constructor body:
|
|
|
|
```dart
|
|
class C {
|
|
static int? a;
|
|
C(int? c) {
|
|
a = c;
|
|
}
|
|
}
|
|
```
|
|
initializingFormalForNonExistentField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String formalName: the name of the initializing formal that is not an instance variable in the immediately enclosing class
|
|
problemMessage: "'#formalName' isn't a field in the enclosing class."
|
|
correctionMessage: "Try correcting the name to match an existing field, or defining a field named '#formalName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an initializing formal
|
|
parameter is found in a constructor in a class that doesn't declare the
|
|
field being initialized. Constructors can't initialize fields that aren't
|
|
declared and fields that are inherited from superclasses.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `x` isn't
|
|
defined:
|
|
|
|
```dart
|
|
class C {
|
|
int? y;
|
|
|
|
C([!this.x!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field name was wrong, then change it to the name of an existing
|
|
field:
|
|
|
|
```dart
|
|
class C {
|
|
int? y;
|
|
|
|
C(this.y);
|
|
}
|
|
```
|
|
|
|
If the field name is correct but hasn't yet been defined, then declare the
|
|
field:
|
|
|
|
```dart
|
|
class C {
|
|
int? x;
|
|
int? y;
|
|
|
|
C(this.x);
|
|
}
|
|
```
|
|
|
|
If the parameter is needed but shouldn't initialize a field, then convert
|
|
it to a normal parameter and use it:
|
|
|
|
```dart
|
|
class C {
|
|
int y;
|
|
|
|
C(int x) : y = x * 2;
|
|
}
|
|
```
|
|
|
|
If the parameter isn't needed, then remove it:
|
|
|
|
```dart
|
|
class C {
|
|
int? y;
|
|
|
|
C();
|
|
}
|
|
```
|
|
instanceAccessToStaticMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the static member
|
|
String memberKind: the kind of the static member (field, getter, setter, or method)
|
|
String enclosingElementName: the name of the static member's enclosing element
|
|
String enclosingElementKind: the kind of the static member's enclosing element (class, mixin, or extension)
|
|
problemMessage: "The static #memberKind '#memberName' can't be accessed through an instance."
|
|
correctionMessage: "Try using the #enclosingElementKind '#enclosingElementName' to access the #memberKind."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an access operator is used to
|
|
access a static member through an instance of the class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `zero` is a static
|
|
field, but it's being accessed as if it were an instance field:
|
|
|
|
```dart
|
|
void f(C c) {
|
|
c.[!zero!];
|
|
}
|
|
|
|
class C {
|
|
static int zero = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use the class to access the static member:
|
|
|
|
```dart
|
|
void f(C c) {
|
|
C.zero;
|
|
}
|
|
|
|
class C {
|
|
static int zero = 0;
|
|
}
|
|
```
|
|
instanceAccessToStaticMemberOfUnnamedExtension:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the static member
|
|
String kind: the kind of the static member (field, getter, setter, or method)
|
|
sharedName: instanceAccessToStaticMember
|
|
problemMessage: "The static #kind '#name' can't be accessed through an instance."
|
|
hasPublishedDocs: true
|
|
instanceMemberAccessFromFactory:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Instance members can't be accessed from a factory constructor."
|
|
correctionMessage: Try removing the reference to the instance member.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a factory constructor contains
|
|
an unqualified reference to an instance member. In a generative
|
|
constructor, the instance of the class is created and initialized before
|
|
the body of the constructor is executed, so the instance can be bound to
|
|
`this` and accessed just like it would be in an instance method. But, in a
|
|
factory constructor, the instance isn't created before executing the body,
|
|
so `this` can't be used to reference it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` isn't in scope in
|
|
the factory constructor:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
factory C() {
|
|
return C._([!x!]);
|
|
}
|
|
C._(this.x);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rewrite the code so that it doesn't reference the instance member:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
factory C() {
|
|
return C._(0);
|
|
}
|
|
C._(this.x);
|
|
}
|
|
```
|
|
instanceMemberAccessFromStatic:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Instance members can't be accessed from a static method."
|
|
correctionMessage: "Try removing the reference to the instance member, or removing the keyword 'static' from the method."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a static method contains an
|
|
unqualified reference to an instance member.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the instance field `x`
|
|
is being referenced in a static method:
|
|
|
|
```dart
|
|
class C {
|
|
int x = 0;
|
|
|
|
static int m() {
|
|
return [!x!];
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the method must reference the instance member, then it can't be static,
|
|
so remove the keyword:
|
|
|
|
```dart
|
|
class C {
|
|
int x = 0;
|
|
|
|
int m() {
|
|
return x;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the method can't be made an instance method, then add a parameter so
|
|
that an instance of the class can be passed in:
|
|
|
|
```dart
|
|
class C {
|
|
int x = 0;
|
|
|
|
static int m(C c) {
|
|
return c.x;
|
|
}
|
|
}
|
|
```
|
|
instantiateAbstractClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Abstract classes can't be instantiated."
|
|
correctionMessage: Try creating an instance of a concrete subtype.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds a constructor
|
|
invocation and the constructor is declared in an abstract class. Even
|
|
though you can't create an instance of an abstract class, abstract classes
|
|
can declare constructors that can be invoked by subclasses.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `C` is an abstract
|
|
class:
|
|
|
|
```dart
|
|
abstract class C {}
|
|
|
|
var c = new [!C!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a concrete subclass of the abstract class that can be used, then
|
|
create an instance of the concrete subclass.
|
|
instantiateEnum:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Enums can't be instantiated."
|
|
correctionMessage: Try using one of the defined constants.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enum is instantiated. It's
|
|
invalid to create an instance of an enum by invoking a constructor; only
|
|
the instances named in the declaration of the enum can exist.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum `E` is being
|
|
instantiated:
|
|
|
|
```dart
|
|
// @dart = 2.16
|
|
enum E {a}
|
|
|
|
var e = [!E!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intend to use an instance of the enum, then reference one of the
|
|
constants defined in the enum:
|
|
|
|
```dart
|
|
// @dart = 2.16
|
|
enum E {a}
|
|
|
|
var e = E.a;
|
|
```
|
|
|
|
If you intend to use an instance of a class, then use the name of that class in place of the name of the enum.
|
|
instantiateTypeAliasExpandsToTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Type aliases that expand to a type parameter can't be instantiated."
|
|
correctionMessage: Try replacing it with a class.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor invocation is
|
|
found where the type being instantiated is a type alias for one of the type
|
|
parameters of the type alias. This isn't allowed because the value of the
|
|
type parameter is a type rather than a class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because it creates an instance
|
|
of `A`, even though `A` is a type alias that is defined to be equivalent to
|
|
a type parameter:
|
|
|
|
```dart
|
|
typedef A<T> = T;
|
|
|
|
void f() {
|
|
const [!A!]<int>();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use either a class name or a type alias defined to be a class, rather than
|
|
a type alias defined to be a type parameter:
|
|
|
|
```dart
|
|
typedef A<T> = C<T>;
|
|
|
|
void f() {
|
|
const A<int>();
|
|
}
|
|
|
|
class C<T> {
|
|
const C();
|
|
}
|
|
```
|
|
integerLiteralImpreciseAsDouble:
|
|
type: compileTimeError
|
|
parameters:
|
|
String literal: the lexeme of the integer
|
|
String closestDouble: the closest valid double
|
|
problemMessage: "The integer literal is being used as a double, but can't be represented as a 64-bit double without overflow or loss of precision: '#literal'."
|
|
correctionMessage: "Try using the class 'BigInt', or switch to the closest valid double: '#closestDouble'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an integer literal is being
|
|
implicitly converted to a double, but can't be represented as a 64-bit
|
|
double without overflow or loss of precision. Integer literals are
|
|
implicitly converted to a double if the context requires the type `double`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the integer value
|
|
`9223372036854775807` can't be represented exactly as a double:
|
|
|
|
```dart
|
|
double x = [!9223372036854775807!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to use the exact value, then use the class `BigInt` to
|
|
represent the value:
|
|
|
|
```dart
|
|
var x = BigInt.parse('9223372036854775807');
|
|
```
|
|
|
|
If you need to use a double, then change the value to one that can be
|
|
represented exactly:
|
|
|
|
```dart
|
|
double x = 9223372036854775808;
|
|
```
|
|
integerLiteralOutOfRange:
|
|
type: compileTimeError
|
|
parameters:
|
|
String literal: the value of the literal
|
|
problemMessage: "The integer literal #literal can't be represented in 64 bits."
|
|
correctionMessage: "Try using the 'BigInt' class if you need an integer larger than 9,223,372,036,854,775,807 or less than -9,223,372,036,854,775,808."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an integer literal has a value
|
|
that is too large (positive) or too small (negative) to be represented in a
|
|
64-bit word.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value can't be
|
|
represented in 64 bits:
|
|
|
|
```dart
|
|
var x = [!9223372036854775810!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to represent the current value, then wrap it in an instance of
|
|
the class `BigInt`:
|
|
|
|
```dart
|
|
var x = BigInt.parse('9223372036854775810');
|
|
```
|
|
interfaceClassExtendedOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the interface class being extended.
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The class '#name' can't be extended outside of its library because it's an interface class."
|
|
hasPublishedDocs: true
|
|
invalidAnnotation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Annotation must be either a const variable reference or const constructor invocation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an annotation is found that is
|
|
using something that is neither a variable marked as `const` or the
|
|
invocation of a `const` constructor.
|
|
|
|
Getters can't be used as annotations.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the variable `v` isn't
|
|
a `const` variable:
|
|
|
|
```dart
|
|
var v = 0;
|
|
|
|
[!@v!]
|
|
void f() {
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `f` isn't a variable:
|
|
|
|
```dart
|
|
[!@f!]
|
|
void f() {
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `f` isn't a
|
|
constructor:
|
|
|
|
```dart
|
|
[!@f()!]
|
|
void f() {
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `g` is a getter:
|
|
|
|
```dart
|
|
[!@g!]
|
|
int get g => 0;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotation is referencing a variable that isn't a `const`
|
|
constructor, add the keyword `const` to the variable's declaration:
|
|
|
|
```dart
|
|
const v = 0;
|
|
|
|
@v
|
|
void f() {
|
|
}
|
|
```
|
|
|
|
If the annotation isn't referencing a variable, then remove it:
|
|
|
|
```dart
|
|
int v = 0;
|
|
|
|
void f() {
|
|
}
|
|
```
|
|
invalidAnnotationConstantValueFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant values from a deferred library can't be used in annotations."
|
|
correctionMessage: "Try moving the constant from the deferred library, or removing 'deferred' from the import."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constant defined in a library
|
|
that is imported as a deferred library is referenced in the argument list
|
|
of an annotation. Annotations 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 constant `pi` is
|
|
being referenced in the argument list of an annotation, even though the
|
|
library that defines it is being imported as a deferred library:
|
|
|
|
```dart
|
|
import 'dart:math' deferred as math;
|
|
|
|
class C {
|
|
const C(double d);
|
|
}
|
|
|
|
@C(math.[!pi!])
|
|
void f () {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to reference the imported constant, then remove the `deferred`
|
|
keyword:
|
|
|
|
```dart
|
|
import 'dart:math' as math;
|
|
|
|
class C {
|
|
const C(double d);
|
|
}
|
|
|
|
@C(math.pi)
|
|
void f () {}
|
|
```
|
|
|
|
If the import is required to be deferred and there's another constant that
|
|
is appropriate, then use that constant in place of the constant from the
|
|
deferred library.
|
|
invalidAnnotationFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant values from a deferred library can't be used as annotations."
|
|
correctionMessage: Try removing the annotation, or changing the import to not be deferred.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constant from a library that
|
|
is imported using a deferred import is used as an annotation. Annotations
|
|
are evaluated at compile time, and constants 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 constant `pi` is
|
|
being used as an annotation when the library `dart:math` is imported as
|
|
`deferred`:
|
|
|
|
```dart
|
|
import 'dart:math' deferred as math;
|
|
|
|
@[!math.pi!]
|
|
void f() {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to reference the constant as an annotation, then remove the
|
|
keyword `deferred` from the import:
|
|
|
|
```dart
|
|
import 'dart:math' as math;
|
|
|
|
@math.pi
|
|
void f() {}
|
|
```
|
|
|
|
If you can use a different constant as an annotation, then replace the
|
|
annotation with a different constant:
|
|
|
|
```dart
|
|
@deprecated
|
|
void f() {}
|
|
```
|
|
invalidAssignment:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualStaticType: the name of the right hand side type
|
|
Type expectedStaticType: the name of the left hand side type
|
|
problemMessage: "A value of type '#actualStaticType' can't be assigned to a variable of type '#expectedStaticType'."
|
|
correctionMessage: "Try changing the type of the variable, or casting the right-hand type to '#expectedStaticType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the static type of an expression
|
|
that is assigned to a variable isn't assignable to the type of the
|
|
variable.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of the
|
|
initializer (`int`) isn't assignable to the type of the variable
|
|
(`String`):
|
|
|
|
```dart
|
|
int i = 0;
|
|
String s = [!i!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the value being assigned is always assignable at runtime, even though
|
|
the static types don't reflect that, then add an explicit cast.
|
|
|
|
Otherwise, change the value being assigned so that it has the expected
|
|
type. In the previous example, this might look like:
|
|
|
|
```dart
|
|
int i = 0;
|
|
String s = i.toString();
|
|
```
|
|
|
|
If you can't change the value, then change the type of the variable to be
|
|
compatible with the type of the value being assigned:
|
|
|
|
```dart
|
|
int i = 0;
|
|
int s = i;
|
|
```
|
|
invalidCastFunction:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the name of the function
|
|
String p1: the type of the function
|
|
String p2: the expected function type
|
|
removedIn: "3.0"
|
|
problemMessage: "The function '#p0' has type '#p1' that isn't of expected type '#p2'. This means its parameter or return type doesn't match what is expected."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastFunctionExpr:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the type of the torn-off function expression
|
|
String p1: the expected function type
|
|
removedIn: "3.0"
|
|
problemMessage: The function expression type '#p0' isn't of type '#p1'. This means its parameter or return type doesn't match what is expected. Consider changing parameter type(s) or the returned type(s).
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastLiteral:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the lexeme of the literal
|
|
String p1: the type of the literal
|
|
String p2: the expected type
|
|
removedIn: "3.0"
|
|
problemMessage: "The literal '#p0' with type '#p1' isn't of expected type '#p2'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastLiteralList:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the type of the list literal
|
|
String p1: the expected type
|
|
removedIn: "3.0"
|
|
problemMessage: "The list literal type '#p0' isn't of expected type '#p1'. The list's type can be changed with an explicit generic type argument or by changing the element types."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastLiteralMap:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the type of the map literal
|
|
String p1: the expected type
|
|
removedIn: "3.0"
|
|
problemMessage: "The map literal type '#p0' isn't of expected type '#p1'. The map's type can be changed with an explicit generic type arguments or by changing the key and value types."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastLiteralSet:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the type of the set literal
|
|
String p1: the expected type
|
|
removedIn: "3.0"
|
|
problemMessage: "The set literal type '#p0' isn't of expected type '#p1'. The set's type can be changed with an explicit generic type argument or by changing the element types."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the name of the torn-off method
|
|
String p1: the type of the torn-off method
|
|
String p2: the expected function type
|
|
removedIn: "3.0"
|
|
problemMessage: "The method tear-off '#p0' has type '#p1' that isn't of expected type '#p2'. This means its parameter or return type doesn't match what is expected."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidCastNewExpr:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the type of the instantiated object
|
|
String p1: the expected type
|
|
removedIn: "3.0"
|
|
problemMessage: "The constructor returns type '#p0' that isn't of expected type '#p1'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This error is only reported in libraries which are not null safe.
|
|
invalidConstant:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Invalid constant value.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
TODO(brianwilkerson): Remove this when we have decided on how to report
|
|
errors in compile-time constants. Until then, this acts as a placeholder
|
|
for more informative errors.
|
|
|
|
See TODOs in ConstantVisitor
|
|
invalidExtensionArgumentCount:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Extension overrides must have exactly one argument: the value of 'this' in the extension method."
|
|
correctionMessage: Try specifying exactly one argument.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override doesn't
|
|
have exactly one argument. The argument is the expression used to compute
|
|
the value of `this` within the extension method, so there must be one
|
|
argument.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because there are no arguments:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String join(String other) => '$this $other';
|
|
}
|
|
|
|
void f() {
|
|
E[!()!].join('b');
|
|
}
|
|
```
|
|
|
|
And, the following code produces this diagnostic because there's more than
|
|
one argument:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String join(String other) => '$this $other';
|
|
}
|
|
|
|
void f() {
|
|
E[!('a', 'b')!].join('c');
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Provide one argument for the extension override:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String join(String other) => '$this $other';
|
|
}
|
|
|
|
void f() {
|
|
E('a').join('b');
|
|
}
|
|
```
|
|
invalidFactoryNameNotAClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The name of a factory constructor must be the same as the name of the immediately enclosing class.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the name of a factory
|
|
constructor isn't the same as the name of the surrounding class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name of the factory
|
|
constructor (`A`) isn't the same as the surrounding class (`C`):
|
|
|
|
```dart
|
|
// @dart = 3.10
|
|
class A {}
|
|
|
|
class C {
|
|
factory [!A!]() => throw 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the factory returns an instance of the surrounding class, and you
|
|
intend it to be an unnamed factory constructor, then rename the factory:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class C {
|
|
factory C() => throw 0;
|
|
}
|
|
```
|
|
|
|
If the factory returns an instance of the surrounding class, and you
|
|
intend it to be a named factory constructor, then prefix the name of the
|
|
factory constructor with the name of the surrounding class:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class C {
|
|
factory C.a() => throw 0;
|
|
}
|
|
```
|
|
|
|
If the factory returns an instance of a different class, then move the
|
|
factory to that class:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() => throw 0;
|
|
}
|
|
|
|
class C {}
|
|
```
|
|
|
|
If the factory returns an instance of a different class, but you can't
|
|
modify that class or don't want to move the factory, then convert it to be
|
|
a static method:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class C {
|
|
static A a() => throw 0;
|
|
}
|
|
```
|
|
invalidFieldNameFromObject:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: invalidFieldName
|
|
problemMessage: Record field names can't be the same as a member from 'Object'.
|
|
correctionMessage: Try using a different name for the field.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either a record literal or a
|
|
record type annotation has a field whose name is invalid. The name is
|
|
invalid if it is:
|
|
- private (starts with `_`)
|
|
- the same as one of the members defined on `Object`
|
|
- the same as the name of a positional field (an exception is made if the
|
|
field is a positional field with the specified name)
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the record literal has
|
|
a field named `toString`, which is a method defined on `Object`:
|
|
|
|
```dart
|
|
var r = (a: 1, [!toString!]: 4);
|
|
```
|
|
|
|
The following code produces this diagnostic because the record type
|
|
annotation has a field named `hashCode`, which is a getter defined on
|
|
`Object`:
|
|
|
|
```dart
|
|
void f(({int a, int [!hashCode!]}) r) {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the record literal has
|
|
a private field named `_a`:
|
|
|
|
```dart
|
|
var r = ([!_a!]: 1, b: 2);
|
|
```
|
|
|
|
The following code produces this diagnostic because the record type
|
|
annotation has a private field named `_a`:
|
|
|
|
```dart
|
|
void f(({int [!_a!], int b}) r) {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the record literal has
|
|
a field named `$1`, which is also the name of a different positional
|
|
parameter:
|
|
|
|
```dart
|
|
var r = (2, [!$1!]: 1);
|
|
```
|
|
|
|
The following code produces this diagnostic because the record type
|
|
annotation has a field named `$1`, which is also the name of a different
|
|
positional parameter:
|
|
|
|
```dart
|
|
void f((int, String, {int [!$1!]}) r) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename the field:
|
|
|
|
```dart
|
|
var r = (a: 1, d: 4);
|
|
```
|
|
invalidFieldNamePrivate:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: invalidFieldName
|
|
problemMessage: Record field names can't be private.
|
|
correctionMessage: Try removing the leading underscore.
|
|
hasPublishedDocs: true
|
|
invalidFieldNamePositional:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: invalidFieldName
|
|
problemMessage: Record field names can't be a dollar sign followed by an integer when the integer is the index of a positional field.
|
|
correctionMessage: Try using a different name for the field.
|
|
hasPublishedDocs: true
|
|
invalidImplementationOverride:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the declared member that is not a valid override.
|
|
String declaringInterfaceName: the name of the interface that declares the member.
|
|
Type typeInDeclaringInterface: the type of the declared member in the interface.
|
|
String overriddenInterfaceName: the name of the interface with the overridden member.
|
|
Type typeInOverriddenInterface: the type of the overridden member.
|
|
problemMessage: "'#declaringInterfaceName.#memberName' ('#typeInDeclaringInterface') isn't a valid concrete implementation of '#overriddenInterfaceName.#memberName' ('#typeInOverriddenInterface')."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
The parameters of this error code must be kept in sync with those of
|
|
[diag.invalidOverride].
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when all of the following are true:
|
|
|
|
- A class defines an abstract member.
|
|
- There is a concrete implementation of that member in a superclass.
|
|
- The concrete implementation isn't a valid implementation of the abstract
|
|
method.
|
|
|
|
The concrete implementation can be invalid because of incompatibilities in
|
|
either the return type, the types of the method's parameters, or the type
|
|
parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `A.add` has
|
|
a parameter of type `int`, and the overriding method `B.add` has a
|
|
corresponding parameter of type `num`:
|
|
|
|
```dart
|
|
class A {
|
|
int add(int a) => a;
|
|
}
|
|
class [!B!] extends A {
|
|
int add(num a);
|
|
}
|
|
```
|
|
|
|
This is a problem because in an invocation of `B.add` like the following:
|
|
|
|
```dart
|
|
void f(B b) {
|
|
b.add(3.4);
|
|
}
|
|
```
|
|
|
|
`B.add` is expecting to be able to take, for example, a `double`, but when
|
|
the method `A.add` is executed (because it's the only concrete
|
|
implementation of `add`), a runtime exception will be thrown because a
|
|
`double` can't be assigned to a parameter of type `int`.
|
|
|
|
#### Common fixes
|
|
|
|
If the method in the subclass can conform to the implementation in the
|
|
superclass, then change the declaration in the subclass (or remove it if
|
|
it's the same):
|
|
|
|
```dart
|
|
class A {
|
|
int add(int a) => a;
|
|
}
|
|
class B extends A {
|
|
int add(int a);
|
|
}
|
|
```
|
|
|
|
If the method in the superclass can be generalized to be a valid
|
|
implementation of the method in the subclass, then change the superclass
|
|
method:
|
|
|
|
```dart
|
|
class A {
|
|
int add(num a) => a.floor();
|
|
}
|
|
class B extends A {
|
|
int add(num a);
|
|
}
|
|
```
|
|
|
|
If neither the method in the superclass nor the method in the subclass can
|
|
be changed, then provide a concrete implementation of the method in the
|
|
subclass:
|
|
|
|
```dart
|
|
class A {
|
|
int add(int a) => a;
|
|
}
|
|
class B extends A {
|
|
int add(num a) => a.floor();
|
|
}
|
|
```
|
|
invalidImplementationOverrideSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the declared setter that is not a valid override.
|
|
String declaringInterfaceName: the name of the interface that declares the setter.
|
|
Type typeInDeclaringInterface: the type of the declared setter in the interface.
|
|
String overriddenInterfaceName: the name of the interface with the overridden setter.
|
|
Type typeInOverriddenInterface: the type of the overridden setter.
|
|
sharedName: invalidImplementationOverride
|
|
problemMessage: "The setter '#declaringInterfaceName.#memberName' ('#typeInDeclaringInterface') isn't a valid concrete implementation of '#overriddenInterfaceName.#memberName' ('#typeInOverriddenInterface')."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
The parameters of this error code must be kept in sync with those of
|
|
[diag.invalidOverride].
|
|
invalidInlineFunctionType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Inline function types can't be used for parameters in a generic function type."
|
|
correctionMessage: "Try using a generic function type (returnType 'Function(' parameters ')')."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a generic function type has a
|
|
function-valued parameter that is written using the older inline function
|
|
type syntax.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the parameter `f`, in
|
|
the generic function type used to define `F`, uses the inline function
|
|
type syntax:
|
|
|
|
```dart
|
|
typedef F = int Function(int f[!(!]String s));
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use the generic function syntax for the parameter's type:
|
|
|
|
```dart
|
|
typedef F = int Function(int Function(String));
|
|
```
|
|
invalidModifierOnConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String modifier: the invalid modifier
|
|
problemMessage: "The modifier '#modifier' can't be applied to the body of a constructor."
|
|
correctionMessage: Try removing the modifier.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of a constructor is
|
|
prefixed by one of the following modifiers: `async`, `async*`, or `sync*`.
|
|
Constructor bodies must be synchronous.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the body of the
|
|
constructor for `C` is marked as being `async`:
|
|
|
|
```dart
|
|
class C {
|
|
C() [!async!] {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the constructor can be synchronous, then remove the modifier:
|
|
|
|
```dart
|
|
class C {
|
|
C();
|
|
}
|
|
```
|
|
|
|
If the constructor can't be synchronous, then use a static method to create
|
|
the instance instead:
|
|
|
|
```dart
|
|
class C {
|
|
C();
|
|
static Future<C> c() async {
|
|
return C();
|
|
}
|
|
}
|
|
```
|
|
invalidModifierOnSetter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Setters can't use 'async', 'async*', or 'sync*'."
|
|
correctionMessage: Try removing the modifier.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of a setter is prefixed
|
|
by one of the following modifiers: `async`, `async*`, or `sync*`. Setter
|
|
bodies must be synchronous.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the body of the setter
|
|
`x` is marked as being `async`:
|
|
|
|
```dart
|
|
class C {
|
|
set x(int i) [!async!] {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the setter can be synchronous, then remove the modifier:
|
|
|
|
```dart
|
|
class C {
|
|
set x(int i) {}
|
|
}
|
|
```
|
|
|
|
If the setter can't be synchronous, then use a method to set the value
|
|
instead:
|
|
|
|
```dart
|
|
class C {
|
|
void x(int i) async {}
|
|
}
|
|
```
|
|
invalidOverride:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the declared member that is not a valid override.
|
|
String declaringInterfaceName: the name of the interface that declares the member.
|
|
Type typeInDeclaringInterface: the type of the declared member in the interface.
|
|
String overriddenInterfaceName: the name of the interface with the overridden member.
|
|
Type typeInOverriddenInterface: the type of the overridden member.
|
|
problemMessage: "'#declaringInterfaceName.#memberName' ('#typeInDeclaringInterface') isn't a valid override of '#overriddenInterfaceName.#memberName' ('#typeInOverriddenInterface')."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member of a class is found
|
|
that overrides a member from a supertype and the override isn't valid. An
|
|
override is valid if all of these are true:
|
|
- It allows all of the arguments allowed by the overridden member.
|
|
- It doesn't require any arguments that aren't required by the overridden
|
|
member.
|
|
- The type of every parameter of the overridden member is assignable to the
|
|
corresponding parameter of the override.
|
|
- The return type of the override is assignable to the return type of the
|
|
overridden member.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of the
|
|
parameter `s` (`String`) isn't assignable to the type of the parameter `i`
|
|
(`int`):
|
|
|
|
```dart
|
|
class A {
|
|
void m(int i) {}
|
|
}
|
|
|
|
class B extends A {
|
|
void [!m!](String s) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the invalid method is intended to override the method from the
|
|
superclass, then change it to conform:
|
|
|
|
```dart
|
|
class A {
|
|
void m(int i) {}
|
|
}
|
|
|
|
class B extends A {
|
|
void m(int i) {}
|
|
}
|
|
```
|
|
|
|
If it isn't intended to override the method from the superclass, then
|
|
rename it:
|
|
|
|
```dart
|
|
class A {
|
|
void m(int i) {}
|
|
}
|
|
|
|
class B extends A {
|
|
void m2(String s) {}
|
|
}
|
|
```
|
|
invalidOverrideSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the declared setter that is not a valid override.
|
|
String declaringInterfaceName: the name of the interface that declares the setter.
|
|
Type typeInDeclaringInterface: the type of the declared setter in the interface.
|
|
String overriddenInterfaceName: the name of the interface with the overridden setter.
|
|
Type typeInOverriddenInterface: the type of the overridden setter.
|
|
sharedName: invalidOverride
|
|
problemMessage: "The setter '#declaringInterfaceName.#memberName' ('#typeInDeclaringInterface') isn't a valid override of '#overriddenInterfaceName.#memberName' ('#typeInOverriddenInterface')."
|
|
hasPublishedDocs: true
|
|
invalidReferenceToGenerativeEnumConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Generative enum constructors can only be used to create an enum constant.
|
|
correctionMessage: Try using an enum value, or a factory constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a generative constructor
|
|
defined on an enum is used anywhere other than to create one of the enum
|
|
constants or as the target of a redirection from another constructor in
|
|
the same enum.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor for
|
|
`E` is being used to create an instance in the function `f`:
|
|
|
|
```dart
|
|
enum E {
|
|
a(0);
|
|
|
|
const E(int x);
|
|
}
|
|
|
|
E f() => const [!E!](2);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's an enum value with the same value, or if you add such a
|
|
constant, then reference the constant directly:
|
|
|
|
```dart
|
|
enum E {
|
|
a(0), b(2);
|
|
|
|
const E(int x);
|
|
}
|
|
|
|
E f() => E.b;
|
|
```
|
|
|
|
If you need to use a constructor invocation, then use a factory
|
|
constructor:
|
|
|
|
```dart
|
|
enum E {
|
|
a(0);
|
|
|
|
const E(int x);
|
|
|
|
factory E.c(int x) => a;
|
|
}
|
|
|
|
E f() => E.c(2);
|
|
```
|
|
invalidReferenceToGenerativeEnumConstructorTearoff:
|
|
type: compileTimeError
|
|
sharedName: invalidReferenceToGenerativeEnumConstructor
|
|
parameters: none
|
|
problemMessage: Generative enum constructors can't be torn off.
|
|
correctionMessage: Try using an enum value, or a factory constructor.
|
|
hasPublishedDocs: true
|
|
invalidReferenceToThis:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Invalid reference to 'this' expression."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when `this` is used outside of an
|
|
instance method or a generative constructor. The reserved word `this` is
|
|
only defined in the context of an instance method, a generative
|
|
constructor, or the initializer of a late instance field declaration.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `v` is a top-level
|
|
variable:
|
|
|
|
```dart
|
|
C f() => [!this!];
|
|
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use a variable of the appropriate type in place of `this`, declaring it if
|
|
necessary:
|
|
|
|
```dart
|
|
C f(C c) => c;
|
|
|
|
class C {}
|
|
```
|
|
invalidSuperFormalParameterLocation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Super parameters can only be used in non-redirecting generative constructors.
|
|
correctionMessage: Try removing the 'super' modifier, or changing the constructor to be non-redirecting and generative.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a super parameter is used
|
|
anywhere other than a non-redirecting generative constructor.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the super parameter
|
|
`x` is in a redirecting generative constructor:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B.b([!super!].x) : this._();
|
|
B._() : super(0);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the super parameter
|
|
`x` isn't in a generative constructor:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class C extends A {
|
|
factory C.c([!super!].x) => C._();
|
|
C._() : super(0);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the super parameter
|
|
`x` is in a method:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class D extends A {
|
|
D() : super(0);
|
|
|
|
void m([!super!].x) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function containing the super parameter can be changed to be a
|
|
non-redirecting generative constructor, then do so:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B.b(super.x);
|
|
}
|
|
```
|
|
|
|
If the function containing the super parameter can't be changed to be a
|
|
non-redirecting generative constructor, then remove the `super`:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class D extends A {
|
|
D() : super(0);
|
|
|
|
void m(int x) {}
|
|
}
|
|
```
|
|
invalidTypeArgumentInConstList:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameter: the name of the type parameter
|
|
sharedName: invalidTypeArgumentInConstLiteral
|
|
problemMessage: "Constant list literals can't use a type parameter in a type argument, such as '#typeParameter'."
|
|
correctionMessage: Try replacing the type parameter with a different type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type parameter is used in a
|
|
type argument in a list, map, or set literal that is prefixed by `const`.
|
|
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.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the type parameter `T`
|
|
is being used as a type argument when creating a constant list:
|
|
|
|
```dart
|
|
List<T> newList<T>() => const <[!T!]>[];
|
|
```
|
|
|
|
The following code produces this diagnostic because the type parameter `T`
|
|
is being used as a type argument when creating a constant map:
|
|
|
|
```dart
|
|
Map<String, T> newSet<T>() => const <String, [!T!]>{};
|
|
```
|
|
|
|
The following code produces this diagnostic because the type parameter `T`
|
|
is being used as a type argument when creating a constant set:
|
|
|
|
```dart
|
|
Set<T> newSet<T>() => const <[!T!]>{};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type that will be used for the type parameter can be known at
|
|
compile time, then remove the type parameter:
|
|
|
|
```dart
|
|
List<int> newList() => const <int>[];
|
|
```
|
|
|
|
If the type that will be used for the type parameter can't be known until
|
|
runtime, then remove the keyword `const`:
|
|
|
|
```dart
|
|
List<T> newList<T>() => <T>[];
|
|
```
|
|
invalidTypeArgumentInConstMap:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameter: the name of the type parameter
|
|
sharedName: invalidTypeArgumentInConstLiteral
|
|
problemMessage: "Constant map literals can't use a type parameter in a type argument, such as '#typeParameter'."
|
|
correctionMessage: Try replacing the type parameter with a different type.
|
|
hasPublishedDocs: true
|
|
invalidTypeArgumentInConstSet:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameter: the name of the type parameter
|
|
sharedName: invalidTypeArgumentInConstLiteral
|
|
problemMessage: "Constant set literals can't use a type parameter in a type argument, such as '#typeParameter'."
|
|
correctionMessage: Try replacing the type parameter with a different type.
|
|
hasPublishedDocs: true
|
|
invalidUri:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uri: the URI that is invalid
|
|
problemMessage: "Invalid URI syntax: '#uri'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a URI in a directive doesn't
|
|
conform to the syntax of a valid URI.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `'#'` isn't a valid
|
|
URI:
|
|
|
|
```dart
|
|
import [!'#'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the invalid URI with a valid URI.
|
|
invalidUseOfCovariant:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The 'covariant' keyword can only be used for parameters in instance methods or before non-final instance fields."
|
|
correctionMessage: "Try removing the 'covariant' keyword."
|
|
hasPublishedDocs: false
|
|
comment: "The 'covariant' keyword was found in an inappropriate location."
|
|
invalidUseOfNullValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "An expression whose value is always 'null' can't be dereferenced."
|
|
correctionMessage: Try changing the type of the expression.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an expression whose value will
|
|
always be `null` is dereferenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` will always be
|
|
`null`:
|
|
|
|
```dart
|
|
int f(Null x) {
|
|
return x.[!length!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the value is allowed to be something other than `null`, then change the
|
|
type of the expression:
|
|
|
|
```dart
|
|
int f(String? x) {
|
|
return x!.length;
|
|
}
|
|
```
|
|
invocationOfExtensionWithoutCall:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the extension
|
|
problemMessage: "The extension '#name' doesn't define a 'call' method so the override can't be used in an invocation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is used to
|
|
invoke a function but the extension doesn't declare a `call` method.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't define a `call` method:
|
|
|
|
```dart
|
|
extension E on String {}
|
|
|
|
void f() {
|
|
[!E('')!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the extension is intended to define a `call` method, then declare it:
|
|
|
|
```dart
|
|
extension E on String {
|
|
int call() => 0;
|
|
}
|
|
|
|
void f() {
|
|
E('')();
|
|
}
|
|
```
|
|
|
|
If the extended type defines a `call` method, then remove the extension
|
|
override.
|
|
|
|
If the `call` method isn't defined, then rewrite the code so that it
|
|
doesn't invoke the `call` method.
|
|
invocationOfNonFunction:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the identifier that is not a function type
|
|
problemMessage: "'#name' isn't a function."
|
|
correctionMessage: "Try correcting the name to match an existing function, or define a method or function named '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds a function invocation,
|
|
but the name of the function being invoked is defined to be something other
|
|
than a function.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `Binary` is the name of
|
|
a function type, not a function:
|
|
|
|
```dart
|
|
typedef Binary = int Function(int, int);
|
|
|
|
int f() {
|
|
return [!Binary!](1, 2);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the name with the name of a function.
|
|
invocationOfNonFunctionExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The expression doesn't evaluate to a function, so it can't be invoked."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function invocation is found,
|
|
but the name being referenced isn't the name of a function, or when the
|
|
expression computing the function doesn't compute a function.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `x` isn't a function:
|
|
|
|
```dart
|
|
int x = 0;
|
|
|
|
int f() => x;
|
|
|
|
var y = [!x!]();
|
|
```
|
|
|
|
The following code produces this diagnostic because `f()` doesn't return a
|
|
function:
|
|
|
|
```dart
|
|
int x = 0;
|
|
|
|
int f() => x;
|
|
|
|
var y = [!f()!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to invoke a function, then replace the code before the argument
|
|
list with the name of a function or with an expression that computes a
|
|
function:
|
|
|
|
```dart
|
|
int x = 0;
|
|
|
|
int f() => x;
|
|
|
|
var y = f();
|
|
```
|
|
labelInOuterScope:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the unresolvable label
|
|
problemMessage: "Can't reference label '#name' declared in an outer method."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `break` or `continue`
|
|
statement references a label that is declared in a method or function
|
|
containing the function in which the `break` or `continue` statement
|
|
appears. The `break` and `continue` statements can't be used to transfer
|
|
control outside the function that contains them.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the label `loop` is
|
|
declared outside the local function `g`:
|
|
|
|
```dart
|
|
void f() {
|
|
loop:
|
|
while (true) {
|
|
void g() {
|
|
break [!loop!];
|
|
}
|
|
|
|
g();
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Try rewriting the code so that it isn't necessary to transfer control
|
|
outside the local function, possibly by inlining the local function:
|
|
|
|
```dart
|
|
void f() {
|
|
loop:
|
|
while (true) {
|
|
break loop;
|
|
}
|
|
}
|
|
```
|
|
|
|
If that isn't possible, then try rewriting the local function so that a
|
|
value returned by the function can be used to determine whether control is
|
|
transferred:
|
|
|
|
```dart
|
|
void f() {
|
|
loop:
|
|
while (true) {
|
|
bool g() {
|
|
return true;
|
|
}
|
|
|
|
if (g()) {
|
|
break loop;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
labelUndefined:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the unresolvable label
|
|
problemMessage: "Can't reference an undefined label '#name'."
|
|
correctionMessage: Try defining the label, or correcting the name to match an existing label.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds a reference to a label
|
|
that isn't defined in the scope of the `break` or `continue` statement that
|
|
is referencing it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the label `loop` isn't
|
|
defined anywhere:
|
|
|
|
```dart
|
|
void f() {
|
|
for (int i = 0; i < 10; i++) {
|
|
for (int j = 0; j < 10; j++) {
|
|
if (j != 0) {
|
|
break [!loop!];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the label should be on the innermost enclosing `do`, `for`, `switch`, or
|
|
`while` statement, then remove the label:
|
|
|
|
```dart
|
|
void f() {
|
|
for (int i = 0; i < 10; i++) {
|
|
for (int j = 0; j < 10; j++) {
|
|
if (j != 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
If the label should be on some other statement, then add the label:
|
|
|
|
```dart
|
|
void f() {
|
|
loop: for (int i = 0; i < 10; i++) {
|
|
for (int j = 0; j < 10; j++) {
|
|
if (j != 0) {
|
|
break loop;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
lateFinalFieldWithConstConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Can't have a late final field in a class with a generative const constructor."
|
|
correctionMessage: "Try removing the 'late' modifier, or don't declare 'const' constructors."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that has at least one
|
|
`const` constructor also has a field marked both `late` and `final`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `A` has a
|
|
`const` constructor and the `final` field `f` is marked as `late`:
|
|
|
|
```dart
|
|
class A {
|
|
[!late!] final int f;
|
|
|
|
const A();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field doesn't need to be marked `late`, then remove the `late`
|
|
modifier from the field:
|
|
|
|
```dart
|
|
class A {
|
|
final int f = 0;
|
|
|
|
const A();
|
|
}
|
|
```
|
|
|
|
If the field must be marked `late`, then remove the `const` modifier from
|
|
the constructors:
|
|
|
|
```dart
|
|
class A {
|
|
late final int f;
|
|
|
|
A();
|
|
}
|
|
```
|
|
lateFinalLocalAlreadyAssigned:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The late final local variable is already assigned.
|
|
correctionMessage: "Try removing the 'final' modifier, or don't reassign the value."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the analyzer can prove that a
|
|
local variable marked as both `late` and `final` was already assigned a
|
|
value at the point where another assignment occurs.
|
|
|
|
Because `final` variables can only be assigned once, subsequent assignments
|
|
are guaranteed to fail, so they're flagged.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `final` variable
|
|
`v` is assigned a value in two places:
|
|
|
|
```dart
|
|
int f() {
|
|
late final int v;
|
|
v = 0;
|
|
[!v!] += 1;
|
|
return v;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to be able to reassign the variable, then remove the `final`
|
|
keyword:
|
|
|
|
```dart
|
|
int f() {
|
|
late int v;
|
|
v = 0;
|
|
v += 1;
|
|
return v;
|
|
}
|
|
```
|
|
|
|
If you don't need to reassign the variable, then remove all except the
|
|
first of the assignments:
|
|
|
|
```dart
|
|
int f() {
|
|
late final int v;
|
|
v = 0;
|
|
return v;
|
|
}
|
|
```
|
|
listElementTypeNotAssignableNullability:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the actual type of the list element
|
|
Type expectedType: the expected type of the list element
|
|
sharedName: listElementTypeNotAssignable
|
|
problemMessage: "The element type '#actualType' can't be assigned to the list type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
listElementTypeNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the actual type of the list element
|
|
Type expectedType: the expected type of the list element
|
|
problemMessage: "The element type '#actualType' can't be assigned to the list type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of an element in a list
|
|
literal isn't assignable to the element type of the list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `2.5` is a double, and
|
|
the list can hold only integers:
|
|
|
|
```dart
|
|
List<int> x = [1, [!2.5!], 3];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended to add a different object to the list, then replace the
|
|
element with an expression that computes the intended object:
|
|
|
|
```dart
|
|
List<int> x = [1, 2, 3];
|
|
```
|
|
|
|
If the object shouldn't be in the list, then remove the element:
|
|
|
|
```dart
|
|
List<int> x = [1, 3];
|
|
```
|
|
|
|
If the object being computed is correct, then widen the element type of the
|
|
list to allow all of the different types of objects it needs to contain:
|
|
|
|
```dart
|
|
List<num> x = [1, 2.5, 3];
|
|
```
|
|
mainFirstPositionalParameterType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The type of the first positional parameter of the 'main' function must be a supertype of 'List<String>'."
|
|
correctionMessage: Try changing the type of the parameter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the first positional parameter
|
|
of a function named `main` isn't a supertype of `List<String>`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `List<int>` isn't a
|
|
supertype of `List<String>`:
|
|
|
|
```dart
|
|
void main([!List<int>!] args) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function is an entry point, then change the type of the first
|
|
positional parameter to be a supertype of `List<String>`:
|
|
|
|
```dart
|
|
void main(List<String> args) {}
|
|
```
|
|
|
|
If the function isn't an entry point, then change the name of the function:
|
|
|
|
```dart
|
|
void f(List<int> args) {}
|
|
```
|
|
mainHasRequiredNamedParameters:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The function 'main' can't have any required named parameters."
|
|
correctionMessage: "Try using a different name for the function, or removing the 'required' modifier."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function named `main` has one
|
|
or more required named parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function named
|
|
`main` has a required named parameter (`x`):
|
|
|
|
```dart
|
|
void [!main!]({required int x}) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function is an entry point, then remove the `required` keyword:
|
|
|
|
```dart
|
|
void main({int? x}) {}
|
|
```
|
|
|
|
If the function isn't an entry point, then change the name of the function:
|
|
|
|
```dart
|
|
void f({required int x}) {}
|
|
```
|
|
mainHasTooManyRequiredPositionalParameters:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The function 'main' can't have more than two required positional parameters."
|
|
correctionMessage: Try using a different name for the function, or removing extra parameters.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function named `main` has more
|
|
than two required positional parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `main` has
|
|
three required positional parameters:
|
|
|
|
```dart
|
|
void [!main!](List<String> args, int x, int y) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function is an entry point and the extra parameters aren't used,
|
|
then remove them:
|
|
|
|
```dart
|
|
void main(List<String> args, int x) {}
|
|
```
|
|
|
|
If the function is an entry point, but the extra parameters used are for
|
|
when the function isn't being used as an entry point, then make the extra
|
|
parameters optional:
|
|
|
|
```dart
|
|
void main(List<String> args, int x, [int y = 0]) {}
|
|
```
|
|
|
|
If the function isn't an entry point, then change the name of the function:
|
|
|
|
```dart
|
|
void f(List<String> args, int x, int y) {}
|
|
```
|
|
mainIsNotFunction:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The declaration named 'main' must be a function."
|
|
correctionMessage: Try using a different name for this declaration.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library contains a declaration
|
|
of the name `main` that isn't the declaration of a top-level function.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `main` is
|
|
being used to declare a top-level variable:
|
|
|
|
```dart
|
|
var [!main!] = 3;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use a different name for the declaration:
|
|
|
|
```dart
|
|
var mainIndex = 3;
|
|
```
|
|
mapEntryNotInMap:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Map entries can only be used in a map literal.
|
|
correctionMessage: Try converting the collection to a map or removing the map entry.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a map entry (a key/value pair)
|
|
is found in a set literal.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the literal has a map
|
|
entry even though it's a set literal:
|
|
|
|
```dart
|
|
var collection = <String>{[!'a' : 'b'!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended for the collection to be a map, then change the code so
|
|
that it is a map. In the previous example, you could do this by adding
|
|
another type argument:
|
|
|
|
```dart
|
|
var collection = <String, String>{'a' : 'b'};
|
|
```
|
|
|
|
In other cases, you might need to change the explicit type from `Set` to
|
|
`Map`.
|
|
|
|
If you intended for the collection to be a set, then remove the map entry,
|
|
possibly by replacing the colon with a comma if both values should be
|
|
included in the set:
|
|
|
|
```dart
|
|
var collection = <String>{'a', 'b'};
|
|
```
|
|
mapKeyTypeNotAssignableNullability:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the type of the expression being used as a key
|
|
Type expectedType: the type of keys declared for the map
|
|
sharedName: mapKeyTypeNotAssignable
|
|
problemMessage: "The element type '#actualType' can't be assigned to the map key type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
mapKeyTypeNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the type of the expression being used as a key
|
|
Type expectedType: the type of keys declared for the map
|
|
problemMessage: "The element type '#actualType' can't be assigned to the map key type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key of a key-value pair in a
|
|
map literal has a type that isn't assignable to the key type of the map.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `2` is an `int`, but
|
|
the keys of the map are required to be `String`s:
|
|
|
|
```dart
|
|
var m = <String, String>{[!2!] : 'a'};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the map is correct, then change the key to have the correct
|
|
type:
|
|
|
|
```dart
|
|
var m = <String, String>{'2' : 'a'};
|
|
```
|
|
|
|
If the type of the key is correct, then change the key type of the map:
|
|
|
|
```dart
|
|
var m = <int, String>{2 : 'a'};
|
|
```
|
|
mapValueTypeNotAssignableNullability:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the type of the expression being used as a value
|
|
Type expectedType: the type of values declared for the map
|
|
sharedName: mapValueTypeNotAssignable
|
|
problemMessage: "The element type '#actualType' can't be assigned to the map value type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
mapValueTypeNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the type of the expression being used as a value
|
|
Type expectedType: the type of values declared for the map
|
|
problemMessage: "The element type '#actualType' can't be assigned to the map value type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a value of a key-value pair in a
|
|
map literal has a type that isn't assignable to the value type of the
|
|
map.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `2` is an `int`, but/
|
|
the values of the map are required to be `String`s:
|
|
|
|
```dart
|
|
var m = <String, String>{'a' : [!2!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the map is correct, then change the value to have the
|
|
correct type:
|
|
|
|
```dart
|
|
var m = <String, String>{'a' : '2'};
|
|
```
|
|
|
|
If the type of the value is correct, then change the value type of the map:
|
|
|
|
```dart
|
|
var m = <String, int>{'a' : 2};
|
|
```
|
|
missingConstInListLiteral:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Seeing this message constitutes a bug. Please report it.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
12.1 Constants: A constant expression is ... a constant list literal.
|
|
|
|
Note: This diagnostic is never displayed to the user, so it doesn't need
|
|
to be documented.
|
|
missingConstInMapLiteral:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Seeing this message constitutes a bug. Please report it.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
12.1 Constants: A constant expression is ... a constant map literal.
|
|
|
|
Note: This diagnostic is never displayed to the user, so it doesn't need
|
|
to be documented.
|
|
missingConstInSetLiteral:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Seeing this message constitutes a bug. Please report it.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
12.1 Constants: A constant expression is ... a constant set literal.
|
|
|
|
Note: This diagnostic is never displayed to the user, so it doesn't need
|
|
to be documented.
|
|
missingDartLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the name of the library
|
|
removedIn: "3.10"
|
|
problemMessage: "Required library '#p0' is missing."
|
|
correctionMessage: Re-install the Dart or Flutter SDK.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either the Dart or Flutter SDK
|
|
isn't installed correctly, and, as a result, one of the `dart:` libraries
|
|
can't be found.
|
|
|
|
#### Common fixes
|
|
|
|
Reinstall the Dart or Flutter SDK.
|
|
missingDefaultValueForParameter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the parameter
|
|
problemMessage: "The parameter '#name' can't have a value of 'null' because of its type, but the implicit default value is 'null'."
|
|
correctionMessage: "Try adding either an explicit non-'null' default value or the 'required' modifier."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an optional parameter, whether
|
|
positional or named, has a [potentially non-nullable][] type and doesn't
|
|
specify a default value. Optional parameters that have no explicit default
|
|
value have an implicit default value of `null`. If the type of the
|
|
parameter doesn't allow the parameter to have a value of `null`, then the
|
|
implicit default value isn't valid.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `x` can't be `null`,
|
|
and no non-`null` default value is specified:
|
|
|
|
```dart
|
|
void f([int [!x!]]) {}
|
|
```
|
|
|
|
As does this:
|
|
|
|
```dart
|
|
void g({int [!x!]}) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to use `null` to indicate that no value was provided, then you
|
|
need to make the type nullable:
|
|
|
|
```dart
|
|
void f([int? x]) {}
|
|
void g({int? x}) {}
|
|
```
|
|
|
|
If the parameter can't be null, then either provide a default value:
|
|
|
|
```dart
|
|
void f([int x = 1]) {}
|
|
void g({int x = 2}) {}
|
|
```
|
|
|
|
or make the parameter a required parameter:
|
|
|
|
```dart
|
|
void f(int x) {}
|
|
void g({required int x}) {}
|
|
```
|
|
missingDefaultValueForParameterPositional:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the parameter
|
|
sharedName: missingDefaultValueForParameter
|
|
problemMessage: "The parameter '#name' can't have a value of 'null' because of its type, but the implicit default value is 'null'."
|
|
correctionMessage: "Try adding an explicit non-'null' default value."
|
|
hasPublishedDocs: true
|
|
missingDefaultValueForParameterWithAnnotation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: missingDefaultValueForParameter
|
|
problemMessage: "With null safety, use the 'required' keyword, not the '@required' annotation."
|
|
correctionMessage: "Try removing the '@'."
|
|
hasPublishedDocs: true
|
|
missingNamedPatternFieldName:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The getter name is not specified explicitly, and the pattern is not a variable.
|
|
correctionMessage: Try specifying the getter name explicitly, or using a variable pattern.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when, within an object pattern, the
|
|
specification of a property and the pattern used to match the property's
|
|
value doesn't have either:
|
|
|
|
- a getter name before the colon
|
|
- a variable pattern from which the getter name can be inferred
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because there is no getter
|
|
name before the colon and no variable pattern after the colon in the
|
|
object pattern (`C(:0)`):
|
|
|
|
```dart
|
|
abstract class C {
|
|
int get f;
|
|
}
|
|
|
|
void f(C c) {
|
|
switch (c) {
|
|
case C([!:0!]):
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to use the actual value of the property within the pattern's
|
|
scope, then add a variable pattern where the name of the variable is the
|
|
same as the name of the property being matched:
|
|
|
|
```dart
|
|
abstract class C {
|
|
int get f;
|
|
}
|
|
|
|
void f(C c) {
|
|
switch (c) {
|
|
case C(:var f) when f == 0:
|
|
print(f);
|
|
}
|
|
}
|
|
```
|
|
|
|
If you don't need to use the actual value of the property within the
|
|
pattern's scope, then add the name of the property being matched before
|
|
the colon:
|
|
|
|
```dart
|
|
abstract class C {
|
|
int get f;
|
|
}
|
|
|
|
void f(C c) {
|
|
switch (c) {
|
|
case C(f: 0):
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
missingRequiredArgument:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the parameter
|
|
problemMessage: "The named parameter '#name' is required, but there's no corresponding argument."
|
|
correctionMessage: Try adding the required argument.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of a function is
|
|
missing a required named parameter.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the invocation of `f`
|
|
doesn't include a value for the required named parameter `end`:
|
|
|
|
```dart
|
|
void f(int start, {required int end}) {}
|
|
void g() {
|
|
[!f!](3);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add a named argument corresponding to the missing required parameter:
|
|
|
|
```dart
|
|
void f(int start, {required int end}) {}
|
|
void g() {
|
|
f(3, end: 5);
|
|
}
|
|
```
|
|
missingVariablePattern:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable pattern
|
|
problemMessage: "Variable pattern '#name' is missing in this branch of the logical-or pattern."
|
|
correctionMessage: "Try declaring this variable pattern in the branch."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when one branch of a logical-or
|
|
pattern doesn't declare a variable that is declared on the other branch of
|
|
the same pattern.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the right-hand side of
|
|
the logical-or pattern doesn't declare the variable `a`:
|
|
|
|
```dart
|
|
void f((int, int) r) {
|
|
if (r case (var a, 0) || [!(0, _)!]) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the variable needs to be referenced in the controlled statements, then
|
|
add a declaration of the variable to every branch of the logical-or
|
|
pattern:
|
|
|
|
```dart
|
|
void f((int, int) r) {
|
|
if (r case (var a, 0) || (0, var a)) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
If the variable doesn't need to be referenced in the controlled
|
|
statements, then remove the declaration of the variable from every branch
|
|
of the logical-or pattern:
|
|
|
|
```dart
|
|
void f((int, int) r) {
|
|
if (r case (_, 0) || (0, _)) {
|
|
print('found a zero');
|
|
}
|
|
}
|
|
```
|
|
|
|
If the variable needs to be referenced if one branch of the pattern
|
|
matches but not when the other matches, then break the pattern into two
|
|
pieces:
|
|
|
|
```dart
|
|
void f((int, int) r) {
|
|
switch (r) {
|
|
case (var a, 0):
|
|
print(a);
|
|
case (0, _):
|
|
print('found a zero');
|
|
}
|
|
}
|
|
```
|
|
mixinsSuperClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
Element referencedClass: the class that appears in both "extends" and "with" clauses
|
|
sharedName: implementsSuperClass
|
|
problemMessage: "'#referencedClass' can't be used in both the 'extends' and 'with' clauses."
|
|
correctionMessage: Try removing one of the occurrences.
|
|
hasPublishedDocs: true
|
|
mixinApplicationConcreteSuperInvokedMemberType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the super-invoked member
|
|
Type mixinMemberType: the display name of the type of the super-invoked member in the mixin
|
|
Type concreteMemberType: the display name of the type of the concrete member in the class
|
|
problemMessage: "The super-invoked member '#memberName' has the type '#mixinMemberType', and the concrete member in the class has the type '#concreteMemberType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin that invokes a method
|
|
using `super` is used in a class where the concrete implementation of that
|
|
method has a different signature than the signature defined for that method
|
|
by the mixin's `on` type. The reason this is an error is because the
|
|
invocation in the mixin might invoke the method in a way that's
|
|
incompatible with the method that will actually be executed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C` uses the
|
|
mixin `M`, the mixin `M` invokes `foo` using `super`, and the abstract
|
|
version of `foo` declared in `I` (the mixin's `on` type) doesn't have the
|
|
same signature as the concrete version of `foo` declared in `A`:
|
|
|
|
```dart
|
|
class I {
|
|
void foo([int? p]) {}
|
|
}
|
|
|
|
class A {
|
|
void foo(int p) {}
|
|
}
|
|
|
|
abstract class B extends A implements I {
|
|
@override
|
|
void foo([int? p]);
|
|
}
|
|
|
|
mixin M on I {
|
|
void bar() {
|
|
super.foo(42);
|
|
}
|
|
}
|
|
|
|
abstract class C extends B with [!M!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the class doesn't need to use the mixin, then remove it from the `with`
|
|
clause:
|
|
|
|
```dart
|
|
class I {
|
|
void foo([int? p]) {}
|
|
}
|
|
|
|
class A {
|
|
void foo(int? p) {}
|
|
}
|
|
|
|
abstract class B extends A implements I {
|
|
@override
|
|
void foo([int? p]);
|
|
}
|
|
|
|
mixin M on I {
|
|
void bar() {
|
|
super.foo(42);
|
|
}
|
|
}
|
|
|
|
abstract class C extends B {}
|
|
```
|
|
|
|
If the class needs to use the mixin, then ensure that there's a concrete
|
|
implementation of the method that conforms to the signature expected by the
|
|
mixin:
|
|
|
|
```dart
|
|
class I {
|
|
void foo([int? p]) {}
|
|
}
|
|
|
|
class A {
|
|
void foo(int? p) {}
|
|
}
|
|
|
|
abstract class B extends A implements I {
|
|
@override
|
|
void foo([int? p]) {
|
|
super.foo(p);
|
|
}
|
|
}
|
|
|
|
mixin M on I {
|
|
void bar() {
|
|
super.foo(42);
|
|
}
|
|
}
|
|
|
|
abstract class C extends B with M {}
|
|
```
|
|
mixinApplicationNotImplementedInterface:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type mixinType: the type of the mixin
|
|
Type superType: the supertype
|
|
Type notImplementedType: the type that is not implemented
|
|
problemMessage: "'#mixinType' can't be mixed onto '#superType' because '#superType' doesn't implement '#notImplementedType'."
|
|
correctionMessage: "Try extending the class '#mixinType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin that has a superclass
|
|
constraint is used in a [mixin application][] with a superclass that
|
|
doesn't implement the required constraint.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the mixin `M` requires
|
|
that the class to which it's applied be a subclass of `A`, but `Object`
|
|
isn't a subclass of `A`:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
mixin M on A {}
|
|
|
|
class X = Object with [!M!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to use the mixin, then change the superclass to be either the
|
|
same as or a subclass of the superclass constraint:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
mixin M on A {}
|
|
|
|
class X = A with M;
|
|
```
|
|
mixinApplicationNoConcreteSuperInvokedSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the display name of the setter without a concrete implementation
|
|
sharedName: mixinApplicationNoConcreteSuperInvokedMember
|
|
problemMessage: "The class doesn't have a concrete implementation of the super-invoked setter '#name'."
|
|
hasPublishedDocs: true
|
|
mixinApplicationNoConcreteSuperInvokedMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the display name of the member without a concrete implementation
|
|
problemMessage: "The class doesn't have a concrete implementation of the super-invoked member '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a [mixin application][] contains
|
|
an invocation of a member from its superclass, and there's no concrete
|
|
member of that name in the mixin application's superclass.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the mixin `M` contains
|
|
the invocation `super.m()`, and the class `A`, which is the superclass of
|
|
the [mixin application][] `A+M`, doesn't define a concrete implementation
|
|
of `m`:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m();
|
|
}
|
|
|
|
mixin M on A {
|
|
void bar() {
|
|
super.m();
|
|
}
|
|
}
|
|
|
|
abstract class B extends A with [!M!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended to apply the mixin `M` to a different class, one that has a
|
|
concrete implementation of `m`, then change the superclass of `B` to that
|
|
class:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m();
|
|
}
|
|
|
|
mixin M on A {
|
|
void bar() {
|
|
super.m();
|
|
}
|
|
}
|
|
|
|
class C implements A {
|
|
void m() {}
|
|
}
|
|
|
|
abstract class B extends C with M {}
|
|
```
|
|
|
|
If you need to make `B` a subclass of `A`, then add a concrete
|
|
implementation of `m` in `A`:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m() {}
|
|
}
|
|
|
|
mixin M on A {
|
|
void bar() {
|
|
super.m();
|
|
}
|
|
}
|
|
|
|
abstract class B extends A with M {}
|
|
```
|
|
mixinClassDeclarationExtendsNotObject:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the mixin class that is invalid
|
|
problemMessage: "The class '#name' can't be declared a mixin because it extends a class other than 'Object'."
|
|
correctionMessage: Try removing the 'mixin' modifier or changing the superclass to 'Object'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that is marked with
|
|
the `mixin` modifier extends a class other than `Object`. A mixin class
|
|
can't have a superclass other than `Object`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B`, which
|
|
has the modifier `mixin`, extends `A`:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
mixin class B extends [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want the class to be used as a mixin, then change the superclass to
|
|
`Object`, either explicitly or by removing the extends clause:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
mixin class B {}
|
|
```
|
|
|
|
If the class needs to have a superclass other than `Object`, then remove
|
|
the `mixin` modifier:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
```
|
|
|
|
If you need both a mixin and a subclass of a class other than `Object`,
|
|
then move the members of the subclass to a new mixin, remove the `mixin`
|
|
modifier from the subclass, and apply the new mixin to the subclass:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B extends A with M {}
|
|
|
|
mixin M {}
|
|
```
|
|
|
|
Depending on the members of the subclass this might require adding an `on`
|
|
clause to the mixin.
|
|
mixinClassDeclarationWithClause:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the mixin class
|
|
problemMessage: "The class '#name' can't be declared a mixin because it has a 'with' clause."
|
|
correctionMessage: Try removing the 'with' clause or removing the 'mixin' modifier from the class.
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class with the `mixin`
|
|
modifier has a `with` clause. A mixin class declaration cannot have a
|
|
`with` clause because that implies it extends a class other than `Object`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `mixin class` `B`
|
|
has a `with` clause:
|
|
|
|
```dart
|
|
mixin M {}
|
|
|
|
mixin class B [!with M!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to use the class as a mixin, remove the `with` clause:
|
|
|
|
```dart
|
|
mixin M {}
|
|
|
|
mixin class B {}
|
|
```
|
|
|
|
If you need the class to have a `with` clause, then remove the `mixin`
|
|
modifier:
|
|
|
|
```dart
|
|
mixin M {}
|
|
|
|
class B with M {}
|
|
```
|
|
mixinModifierMixinApplicationClassWithMultipleMixins:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the mixin class
|
|
problemMessage: "The mixin application class '#name' can only have a single mixin."
|
|
correctionMessage: Try removing all but one mixin.
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin application class
|
|
with the `mixin` modifier has more than one mixin. A mixin class
|
|
application can only have a single mixin.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `mixin class C`
|
|
has multiple mixins:
|
|
|
|
```dart
|
|
mixin M1 {}
|
|
mixin M2 {}
|
|
|
|
mixin class C = Object [!with M1, M2!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to use multiple mixins, remove the `mixin` modifier from the
|
|
mixin application class:
|
|
|
|
```dart
|
|
mixin M1 {}
|
|
mixin M2 {}
|
|
|
|
class C = Object with M1, M2;
|
|
```
|
|
|
|
If you need the class to be a `mixin class`, then only use a single mixin:
|
|
|
|
```dart
|
|
mixin M1 {}
|
|
|
|
mixin class C = Object with M1;
|
|
```
|
|
mixinClassDeclaresConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the mixin that is invalid
|
|
problemMessage: "The class '#className' can't be used as a mixin because it declares a constructor."
|
|
hasPublishedDocs: true
|
|
removedIn: "3.11"
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class is used as a mixin and
|
|
the mixed-in class defines a constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `A`, which
|
|
defines a constructor, is being used as a mixin:
|
|
|
|
```dart
|
|
//@dart=2.19
|
|
class A {
|
|
A();
|
|
}
|
|
|
|
class B with [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If it's possible to convert the class to a mixin, then do so:
|
|
|
|
```dart
|
|
mixin A {
|
|
}
|
|
|
|
class B with A {}
|
|
```
|
|
|
|
If the class can't be a mixin and it's possible to remove the constructor,
|
|
then do so:
|
|
|
|
```dart
|
|
//@dart=2.19
|
|
class A {
|
|
}
|
|
|
|
class B with A {}
|
|
```
|
|
|
|
If the class can't be a mixin and you can't remove the constructor, then
|
|
try extending or implementing the class rather than mixing it in:
|
|
|
|
```dart
|
|
class A {
|
|
A();
|
|
}
|
|
|
|
class B extends A {}
|
|
```
|
|
mixinClassDeclaresNonTrivialGenerativeConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the mixin class
|
|
problemMessage: "The mixin class '#className' can't declare a non-trivial generative constructor."
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin class declares a non-trivial
|
|
generative constructor. Trivial constructors are allowed, but non-trivial ones
|
|
(those with parameters, bodies, or initializers) aren't.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `mixin class` `A`
|
|
defines a generative constructor with a body:
|
|
|
|
```dart
|
|
mixin class A {
|
|
[!A!]() {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can remove the body or parameters of the constructor to make it trivial,
|
|
then do so:
|
|
|
|
```dart
|
|
mixin class A {
|
|
A(); // Trivial constructor
|
|
}
|
|
```
|
|
|
|
If the constructor can't be made trivial, then convert the `mixin class` to a
|
|
regular `class` and extend or implement it, or separate the mixin capability:
|
|
|
|
```dart
|
|
class A {
|
|
A() {}
|
|
}
|
|
|
|
mixin class AM { // A separate mixin for mixing in behavior
|
|
}
|
|
```
|
|
mixinInheritsFromNotObject:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the mixin that is invalid
|
|
problemMessage: "The class '#name' can't be used as a mixin because it extends a class other than 'Object'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that extends a class
|
|
other than `Object` is used as a mixin.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B`, which
|
|
extends `A`, is being used as a mixin by `C`:
|
|
|
|
```dart
|
|
//@dart=2.19
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
|
|
class C with [!B!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the class being used as a mixin can be changed to extend `Object`, then
|
|
change it:
|
|
|
|
```dart
|
|
//@dart=2.19
|
|
class A {}
|
|
|
|
class B {}
|
|
|
|
class C with B {}
|
|
```
|
|
|
|
If the class being used as a mixin can't be changed and the class that's
|
|
using it extends `Object`, then extend the class being used as a mixin:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B extends A {}
|
|
|
|
class C extends B {}
|
|
```
|
|
|
|
If the class doesn't extend `Object` or if you want to be able to mix in
|
|
the behavior from `B` in other places, then create a real mixin:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
mixin M on A {}
|
|
|
|
class B extends A with M {}
|
|
|
|
class C extends A with M {}
|
|
```
|
|
mixinInstantiate:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Mixins can't be instantiated."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin is instantiated.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the mixin `M` is being
|
|
instantiated:
|
|
|
|
```dart
|
|
mixin M {}
|
|
|
|
var m = [!M!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intend to use an instance of a class, then use the name of that
|
|
class in place of the name of the mixin.
|
|
mixinOfNonClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Classes can only mix in mixins and classes.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name in a `with` clause is
|
|
defined to be something other than a mixin or a class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `F` is defined to be a
|
|
function type:
|
|
|
|
```dart
|
|
typedef F = int Function(String);
|
|
|
|
class C with [!F!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the invalid name from the list, possibly replacing it with the name
|
|
of the intended mixin or class:
|
|
|
|
```dart
|
|
typedef F = int Function(String);
|
|
|
|
class C {}
|
|
```
|
|
mixinSubtypeOfBaseIsNotBase:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subtypeName: the name of the mixin that is not 'base'
|
|
String supertypeName: the name of the 'base' supertype
|
|
sharedName: subtypeOfBaseOrFinalIsNotBaseFinalOrSealed
|
|
problemMessage: "The mixin '#subtypeName' must be 'base' because the supertype '#supertypeName' is 'base'."
|
|
hasPublishedDocs: true
|
|
mixinSubtypeOfFinalIsNotBase:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subtypeName: the name of the mixin that is not 'final'
|
|
String supertypeName: the name of the 'final' supertype
|
|
sharedName: subtypeOfBaseOrFinalIsNotBaseFinalOrSealed
|
|
problemMessage: "The mixin '#subtypeName' must be 'base' because the supertype '#supertypeName' is 'final'."
|
|
hasPublishedDocs: true
|
|
mixinSuperClassConstraintDeferredClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Deferred classes can't be used as superclass constraints."
|
|
correctionMessage: Try changing the import to not be deferred.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a superclass constraint of a
|
|
mixin is imported from a deferred library.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the superclass
|
|
constraint of `math.Random` is imported from a deferred library:
|
|
|
|
```dart
|
|
import 'dart:async' deferred as async;
|
|
|
|
mixin M<T> on [!async.Stream<T>!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the import doesn't need to be deferred, then remove the `deferred`
|
|
keyword:
|
|
|
|
```dart
|
|
import 'dart:async' as async;
|
|
|
|
mixin M<T> on async.Stream<T> {}
|
|
```
|
|
|
|
If the import does need to be deferred, then remove the superclass
|
|
constraint:
|
|
|
|
```dart
|
|
mixin M<T> {}
|
|
```
|
|
mixinSuperClassConstraintNonInterface:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Only classes and mixins can be used as superclass constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type following the `on`
|
|
keyword in a mixin declaration is neither a class nor a mixin.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `F` is neither a class
|
|
nor a mixin:
|
|
|
|
```dart
|
|
typedef F = void Function();
|
|
|
|
mixin M on [!F!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type was intended to be a class but was mistyped, then replace the
|
|
name.
|
|
|
|
Otherwise, remove the type from the `on` clause.
|
|
mixinWithNonClassSuperclass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Mixin can only be applied to class.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
9.1 Mixin Application: It is a compile-time error if <i>S</i> does not
|
|
denote a class available in the immediately enclosing scope.
|
|
multipleRedirectingConstructorInvocations:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Constructors can have only one 'this' redirection, at most.
|
|
correctionMessage: Try removing all but one of the redirections.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor redirects to more
|
|
than one other constructor in the same class (using `this`).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the unnamed
|
|
constructor in `C` is redirecting to both `this.a` and `this.b`:
|
|
|
|
```dart
|
|
class C {
|
|
C() : this.a(), [!this.b()!];
|
|
C.a();
|
|
C.b();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the redirections:
|
|
|
|
```dart
|
|
class C {
|
|
C() : this.a();
|
|
C.a();
|
|
C.b();
|
|
}
|
|
```
|
|
multipleSuperInitializers:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A constructor can have at most one 'super' initializer."
|
|
correctionMessage: "Try removing all but one of the 'super' initializers."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the initializer list of a
|
|
constructor contains more than one invocation of a constructor from the
|
|
superclass. The initializer list is required to have exactly one such call,
|
|
which can either be explicit or implicit.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the initializer list
|
|
for `B`'s constructor invokes both the constructor `one` and the
|
|
constructor `two` from the superclass `A`:
|
|
|
|
```dart
|
|
class A {
|
|
int? x;
|
|
String? s;
|
|
A.one(this.x);
|
|
A.two(this.s);
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super.one(0), [!super.two('')!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If one of the super constructors will initialize the instance fully, then
|
|
remove the other:
|
|
|
|
```dart
|
|
class A {
|
|
int? x;
|
|
String? s;
|
|
A.one(this.x);
|
|
A.two(this.s);
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super.one(0);
|
|
}
|
|
```
|
|
|
|
If the initialization achieved by one of the super constructors can be
|
|
performed in the body of the constructor, then remove its super invocation
|
|
and perform the initialization in the body:
|
|
|
|
```dart
|
|
class A {
|
|
int? x;
|
|
String? s;
|
|
A.one(this.x);
|
|
A.two(this.s);
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super.one(0) {
|
|
s = '';
|
|
}
|
|
}
|
|
```
|
|
|
|
If the initialization can only be performed in a constructor in the
|
|
superclass, then either add a new constructor or modify one of the existing
|
|
constructors so there's a constructor that allows all the required
|
|
initialization to occur in a single call:
|
|
|
|
```dart
|
|
class A {
|
|
int? x;
|
|
String? s;
|
|
A.one(this.x);
|
|
A.two(this.s);
|
|
A.three(this.x, this.s);
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super.three(0, '');
|
|
}
|
|
```
|
|
newWithUndefinedConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeName: the name of the class being instantiated
|
|
String constructorName: the name of the constructor
|
|
problemMessage: "The class '#typeName' doesn't have a constructor named '#constructorName'."
|
|
correctionMessage: "Try invoking a different constructor, or define a constructor named '#constructorName'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
12.11.1 New: If <i>T</i> is a class or parameterized type accessible in the
|
|
current scope then:
|
|
1. If <i>e</i> is of the form <i>new T.id(a<sub>1</sub>, …,
|
|
a<sub>n</sub>, x<sub>n+1</sub>: a<sub>n+1</sub>, …,
|
|
x<sub>n+k</sub>: a<sub>n+k</sub>)</i> it is a static warning if
|
|
<i>T.id</i> is not the name of a constructor declared by the type
|
|
<i>T</i>.
|
|
If <i>e</i> of the form <i>new T(a<sub>1</sub>, …, a<sub>n</sub>,
|
|
x<sub>n+1</sub>: a<sub>n+1</sub>, …, x<sub>n+k</sub>:
|
|
a<sub>n+kM/sub>)</i> it is a static warning if the type <i>T</i> does not
|
|
declare a constructor with the same name as the declaration of <i>T</i>.
|
|
newWithUndefinedConstructorDefault:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class being instantiated
|
|
problemMessage: "The class '#className' doesn't have an unnamed constructor."
|
|
correctionMessage: "Try using one of the named constructors defined in '#className'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an unnamed constructor is
|
|
invoked on a class that defines named constructors but the class doesn't
|
|
have an unnamed constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A` doesn't define an
|
|
unnamed constructor:
|
|
|
|
```dart
|
|
class A {
|
|
A.a();
|
|
}
|
|
|
|
A f() => [!A!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If one of the named constructors does what you need, then use it:
|
|
|
|
```dart
|
|
class A {
|
|
A.a();
|
|
}
|
|
|
|
A f() => A.a();
|
|
```
|
|
|
|
If none of the named constructors does what you need, and you're able to
|
|
add an unnamed constructor, then add the constructor:
|
|
|
|
```dart
|
|
class A {
|
|
A();
|
|
A.a();
|
|
}
|
|
|
|
A f() => A();
|
|
```
|
|
nonAbstractClassInheritsAbstractMemberFivePlus:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name1: the name of the first member
|
|
String name2: the name of the second member
|
|
String name3: the name of the third member
|
|
String name4: the name of the fourth member
|
|
int remainingCount: the number of additional missing members that aren't listed
|
|
sharedName: nonAbstractClassInheritsAbstractMember
|
|
problemMessage: "Missing concrete implementations of '#name1', '#name2', '#name3', '#name4', and #remainingCount more."
|
|
correctionMessage: Try implementing the missing methods, or make the class abstract.
|
|
hasPublishedDocs: true
|
|
nonAbstractClassInheritsAbstractMemberFour:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name1: the name of the first member
|
|
String name2: the name of the second member
|
|
String name3: the name of the third member
|
|
String name4: the name of the fourth member
|
|
sharedName: nonAbstractClassInheritsAbstractMember
|
|
problemMessage: "Missing concrete implementations of '#name1', '#name2', '#name3', and '#name4'."
|
|
correctionMessage: Try implementing the missing methods, or make the class abstract.
|
|
hasPublishedDocs: true
|
|
nonAbstractClassInheritsAbstractMemberOne:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the member
|
|
sharedName: nonAbstractClassInheritsAbstractMember
|
|
problemMessage: "Missing concrete implementation of '#name'."
|
|
correctionMessage: Try implementing the missing method, or make the class abstract.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a concrete class inherits one or
|
|
more abstract members, and doesn't provide or inherit an implementation for
|
|
at least one of those abstract members.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B` doesn't
|
|
have a concrete implementation of `m`:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m();
|
|
}
|
|
|
|
class [!B!] extends A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the subclass can provide a concrete implementation for some or all of
|
|
the abstract inherited members, then add the concrete implementations:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m();
|
|
}
|
|
|
|
class B extends A {
|
|
void m() {}
|
|
}
|
|
```
|
|
|
|
If there is a mixin that provides an implementation of the inherited
|
|
methods, then apply the mixin to the subclass:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m();
|
|
}
|
|
|
|
class B extends A with M {}
|
|
|
|
mixin M {
|
|
void m() {}
|
|
}
|
|
```
|
|
|
|
If the subclass can't provide a concrete implementation for all of the
|
|
abstract inherited members, then mark the subclass as being abstract:
|
|
|
|
```dart
|
|
abstract class A {
|
|
void m();
|
|
}
|
|
|
|
abstract class B extends A {}
|
|
```
|
|
nonAbstractClassInheritsAbstractMemberThree:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name1: the name of the first member
|
|
String name2: the name of the second member
|
|
String name3: the name of the third member
|
|
sharedName: nonAbstractClassInheritsAbstractMember
|
|
problemMessage: "Missing concrete implementations of '#name1', '#name2', and '#name3'."
|
|
correctionMessage: Try implementing the missing methods, or make the class abstract.
|
|
hasPublishedDocs: true
|
|
nonAbstractClassInheritsAbstractMemberTwo:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name1: the name of the first member
|
|
String name2: the name of the second member
|
|
sharedName: nonAbstractClassInheritsAbstractMember
|
|
problemMessage: "Missing concrete implementations of '#name1' and '#name2'."
|
|
correctionMessage: Try implementing the missing methods, or make the class abstract.
|
|
hasPublishedDocs: true
|
|
nonBoolCondition:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Conditions must have a static type of 'bool'."
|
|
correctionMessage: Try changing the condition.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a condition, such as an `if` or
|
|
`while` loop, doesn't have the static type `bool`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` has the static type
|
|
`int`:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if ([!x!]) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the condition so that it produces a Boolean value:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x == 0) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
nonBoolExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The expression in an assert must be of type 'bool'."
|
|
correctionMessage: Try changing the expression.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the first expression in an
|
|
assert has a type other than `bool`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of `p` is
|
|
`int`, but a `bool` is required:
|
|
|
|
```dart
|
|
void f(int p) {
|
|
assert([!p!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the expression so that it has the type `bool`:
|
|
|
|
```dart
|
|
void f(int p) {
|
|
assert(p > 0);
|
|
}
|
|
```
|
|
nonBoolNegationExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A negation operand must have a static type of 'bool'."
|
|
correctionMessage: "Try changing the operand to the '!' operator."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the operand of the unary
|
|
negation operator (`!`) doesn't have the type `bool`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` is an `int` when it
|
|
must be a `bool`:
|
|
|
|
```dart
|
|
int x = 0;
|
|
bool y = ![!x!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the operand with an expression that has the type `bool`:
|
|
|
|
```dart
|
|
int x = 0;
|
|
bool y = !(x > 0);
|
|
```
|
|
nonBoolOperand:
|
|
type: compileTimeError
|
|
parameters:
|
|
String operator: the lexeme of the logical operator
|
|
problemMessage: "The operands of the operator '#operator' must be assignable to 'bool'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when one of the operands of either
|
|
the `&&` or `||` operator doesn't have the type `bool`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `a` isn't a Boolean
|
|
value:
|
|
|
|
```dart
|
|
int a = 3;
|
|
bool b = [!a!] || a > 1;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the operand to a Boolean value:
|
|
|
|
```dart
|
|
int a = 3;
|
|
bool b = a == 0 || a > 1;
|
|
```
|
|
nonConstantAnnotationConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Annotation creation can only call a const constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an annotation is the invocation
|
|
of an existing constructor even though the invoked constructor isn't a
|
|
const constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor for `C`
|
|
isn't a const constructor:
|
|
|
|
```dart
|
|
[!@C()!]
|
|
void f() {
|
|
}
|
|
|
|
class C {
|
|
C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If it's valid for the class to have a const constructor, then create a
|
|
const constructor that can be used for the annotation:
|
|
|
|
```dart
|
|
@C()
|
|
void f() {
|
|
}
|
|
|
|
class C {
|
|
const C();
|
|
}
|
|
```
|
|
|
|
If it isn't valid for the class to have a const constructor, then either
|
|
remove the annotation or use a different class for the annotation.
|
|
nonConstantCaseExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Case expressions must be constant.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the expression in a `case`
|
|
clause isn't a constant expression.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `j` isn't a constant:
|
|
|
|
```dart
|
|
%language=2.18
|
|
void f(int i, int j) {
|
|
switch (i) {
|
|
case [!j!]:
|
|
// ...
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Either make the expression a constant expression, or rewrite the `switch`
|
|
statement as a sequence of `if` statements:
|
|
|
|
```dart
|
|
void f(int i, int j) {
|
|
if (i == j) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
nonConstantCaseExpressionFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant values from a deferred library can't be used as a case expression."
|
|
correctionMessage: Try re-writing the switch as a series of if statements, or changing the import to not be deferred.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the expression in a case clause
|
|
references a constant from a library that is imported using a deferred
|
|
import. In order for switch statements to be compiled efficiently, the
|
|
constants referenced in case clauses need to be available at compile time,
|
|
and constants 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 library `a.dart` is
|
|
imported using a `deferred` import, and the constant `a.zero`, declared in
|
|
the imported library, is used in a case clause:
|
|
|
|
```dart
|
|
%language=2.18
|
|
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;
|
|
}
|
|
}
|
|
```
|
|
nonConstantDefaultValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The default value of an optional parameter must be constant.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an optional parameter, either
|
|
named or positional, has a default value that isn't a compile-time
|
|
constant.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
var defaultValue = 3;
|
|
|
|
void f([int value = [!defaultValue!]]) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the default value can be converted to be a constant, then convert it:
|
|
|
|
```dart
|
|
const defaultValue = 3;
|
|
|
|
void f([int value = defaultValue]) {}
|
|
```
|
|
|
|
If the default value needs to change over time, then apply the default
|
|
value inside the function:
|
|
|
|
```dart
|
|
var defaultValue = 3;
|
|
|
|
void f([int? value]) {
|
|
value ??= defaultValue;
|
|
}
|
|
```
|
|
nonConstantDefaultValueFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant values from a deferred library can't be used as a default parameter value."
|
|
correctionMessage: Try leaving the default as 'null' and initializing the parameter inside the function body.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the default value of an optional
|
|
parameter uses a constant from a library imported using a deferred import.
|
|
Default values need to be available at compile time, and constants 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 `zero` is declared in a
|
|
library imported using a deferred import:
|
|
|
|
```dart
|
|
import 'a.dart' deferred as a;
|
|
|
|
void f({int x = a.[!zero!]}) {}
|
|
```
|
|
|
|
#### 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 = a.zero}) {}
|
|
```
|
|
|
|
If you don't need to reference the constant, then replace the default
|
|
value:
|
|
|
|
```dart
|
|
void f({int x = 0}) {}
|
|
```
|
|
nonConstantListElement:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The values in a const list literal must be constants.
|
|
correctionMessage: "Try removing the keyword 'const' from the list literal."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an element in a constant list
|
|
literal isn't a constant value. The list literal can be constant either
|
|
explicitly (because it's prefixed by the `const` keyword) or implicitly
|
|
(because it appears in a [constant context][]).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` isn't a constant,
|
|
even though it appears in an implicitly constant list literal:
|
|
|
|
```dart
|
|
var x = 2;
|
|
var y = const <int>[0, 1, [!x!]];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the list needs to be a constant list, then convert the element to be a
|
|
constant. In the example above, you might add the `const` keyword to the
|
|
declaration of `x`:
|
|
|
|
```dart
|
|
const x = 2;
|
|
var y = const <int>[0, 1, x];
|
|
```
|
|
|
|
If the expression can't be made a constant, then the list can't be a
|
|
constant either, so you must change the code so that the list isn't a
|
|
constant. In the example above this means removing the `const` keyword
|
|
before the list literal:
|
|
|
|
```dart
|
|
var x = 2;
|
|
var y = <int>[0, 1, x];
|
|
```
|
|
nonConstantMapElement:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The elements in a const map literal must be constant.
|
|
correctionMessage: "Try removing the keyword 'const' from the map literal."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `if` element or a spread
|
|
element in a constant map isn't a constant element.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because it's attempting to
|
|
spread a non-constant map:
|
|
|
|
```dart
|
|
var notConst = <int, int>{};
|
|
var map = const <int, int>{...[!notConst!]};
|
|
```
|
|
|
|
Similarly, the following code produces this diagnostic because the
|
|
condition in the `if` element isn't a constant expression:
|
|
|
|
```dart
|
|
bool notConst = true;
|
|
var map = const <int, int>{if ([!notConst!]) 1 : 2};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the map needs to be a constant map, then make the elements constants.
|
|
In the spread example, you might do that by making the collection being
|
|
spread a constant:
|
|
|
|
```dart
|
|
const notConst = <int, int>{};
|
|
var map = const <int, int>{...notConst};
|
|
```
|
|
|
|
If the map doesn't need to be a constant map, then remove the `const`
|
|
keyword:
|
|
|
|
```dart
|
|
bool notConst = true;
|
|
var map = <int, int>{if (notConst) 1 : 2};
|
|
```
|
|
nonConstantMapKey:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The keys in a const map literal must be constant.
|
|
correctionMessage: "Try removing the keyword 'const' from the map literal."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key in a constant map literal
|
|
isn't a constant value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `a` isn't a constant:
|
|
|
|
```dart
|
|
var a = 'a';
|
|
var m = const {[!a!]: 0};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the map needs to be a constant map, then make the key a constant:
|
|
|
|
```dart
|
|
const a = 'a';
|
|
var m = const {a: 0};
|
|
```
|
|
|
|
If the map doesn't need to be a constant map, then remove the `const`
|
|
keyword:
|
|
|
|
```dart
|
|
var a = 'a';
|
|
var m = {a: 0};
|
|
```
|
|
nonConstantMapPatternKey:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Key expressions in map patterns must be constants.
|
|
correctionMessage: Try using constants instead.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key in a map pattern isn't a
|
|
constant expression.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the key `A()` isn't a
|
|
constant:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
if (x case {[!A()!]: 0}) {}
|
|
}
|
|
|
|
class A {
|
|
const A();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use a constant for the key:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
if (x case {const A(): 0}) {}
|
|
}
|
|
|
|
class A {
|
|
const A();
|
|
}
|
|
```
|
|
nonConstantMapValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The values in a const map literal must be constant.
|
|
correctionMessage: "Try removing the keyword 'const' from the map literal."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a value in a constant map
|
|
literal isn't a constant value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `a` isn't a constant:
|
|
|
|
```dart
|
|
var a = 'a';
|
|
var m = const {0: [!a!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the map needs to be a constant map, then make the key a constant:
|
|
|
|
```dart
|
|
const a = 'a';
|
|
var m = const {0: a};
|
|
```
|
|
|
|
If the map doesn't need to be a constant map, then remove the `const`
|
|
keyword:
|
|
|
|
```dart
|
|
var a = 'a';
|
|
var m = {0: a};
|
|
```
|
|
nonConstantRecordField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The fields in a const record literal must be constants.
|
|
correctionMessage: "Try removing the keyword 'const' from the record literal."
|
|
hasPublishedDocs: false
|
|
nonConstantRelationalPatternExpression:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The relational pattern expression must be a constant.
|
|
correctionMessage: Try using a constant instead.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value in a relational
|
|
pattern expression isn't a constant expression.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the operand of the `>`
|
|
operator, `a`, isn't a constant:
|
|
|
|
```dart
|
|
final a = 0;
|
|
|
|
void f(int x) {
|
|
if (x case > [!a!]) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the value with a constant expression:
|
|
|
|
```dart
|
|
const a = 0;
|
|
|
|
void f(int x) {
|
|
if (x case > a) {}
|
|
}
|
|
```
|
|
nonConstantSetElement:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The values in a const set literal must be constants.
|
|
correctionMessage: "Try removing the keyword 'const' from the set literal."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constant set literal contains
|
|
an element that isn't a compile-time constant.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `i` isn't a constant:
|
|
|
|
```dart
|
|
var i = 0;
|
|
|
|
var s = const {[!i!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the element can be changed to be a constant, then change it:
|
|
|
|
```dart
|
|
const i = 0;
|
|
|
|
var s = const {i};
|
|
```
|
|
|
|
If the element can't be a constant, then remove the keyword `const`:
|
|
|
|
```dart
|
|
var i = 0;
|
|
|
|
var s = {i};
|
|
```
|
|
nonConstMapAsExpressionStatement:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A non-constant map or set literal without type arguments can't be used as an expression statement."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
13.2 Expression Statements: It is a compile-time error if a non-constant
|
|
map literal that has no explicit type arguments appears in a place where a
|
|
statement is expected.
|
|
nonCovariantTypeParameterPositionInRepresentationType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "An extension type parameter can't be used in a non-covariant position of its representation type."
|
|
correctionMessage: "Try removing the type parameters from function parameter types and type parameter bounds."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type parameter of an
|
|
extension type is used in a non-covariant position in the representation
|
|
type of that extension type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type parameter `T`
|
|
is used as a parameter type in the function type `void Function(T)`, and
|
|
parameters are not covariant:
|
|
|
|
```dart
|
|
extension type A<[!T!]>(void Function(T) f) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the use of the type parameter:
|
|
|
|
```dart
|
|
extension type A(void Function(String) f) {}
|
|
```
|
|
nonExhaustiveSwitchExpression:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type of the switch scrutinee
|
|
String unmatchedPattern: the witness pattern for the unmatched value
|
|
String suggestedPattern: the suggested pattern for the unmatched value
|
|
problemMessage: "The type '#type' isn't exhaustively matched by the switch cases since it doesn't match the pattern '#unmatchedPattern'."
|
|
correctionMessage: "Try adding a wildcard pattern or cases that match '#suggestedPattern'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `switch` expression is
|
|
missing a case for one or more of the possible values that could flow
|
|
through it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the switch expression
|
|
doesn't have a case for the value `E.three`:
|
|
|
|
```dart
|
|
enum E { one, two, three }
|
|
|
|
String f(E e) => [!switch!] (e) {
|
|
E.one => 'one',
|
|
E.two => 'two',
|
|
};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the missing values are distinctly meaningful to the switch expression,
|
|
then add a case for each of the values missing a match:
|
|
|
|
```dart
|
|
enum E { one, two, three }
|
|
|
|
String f(E e) => switch (e) {
|
|
E.one => 'one',
|
|
E.two => 'two',
|
|
E.three => 'three',
|
|
};
|
|
```
|
|
|
|
If the missing values don't need to be matched, then add a wildcard
|
|
pattern that returns a simple default:
|
|
|
|
```dart
|
|
enum E { one, two, three }
|
|
|
|
String f(E e) => switch (e) {
|
|
E.one => 'one',
|
|
E.two => 'two',
|
|
_ => 'unknown',
|
|
};
|
|
```
|
|
|
|
Be aware that a wildcard pattern will handle any values added to the type
|
|
in the future. You will lose the ability to have the compiler warn you if
|
|
the `switch` needs to be updated to account for newly added types.
|
|
nonExhaustiveSwitchExpressionPrivate:
|
|
type: compileTimeError
|
|
sharedName: nonExhaustiveSwitchExpression
|
|
parameters:
|
|
Type type: the type of the switch scrutinee
|
|
problemMessage: "The enum '#type' isn't exhaustively matched by the switch cases because some of the enum constants are private."
|
|
correctionMessage: "Try adding a wildcard pattern."
|
|
hasPublishedDocs: true
|
|
nonExhaustiveSwitchStatement:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type of the switch scrutinee
|
|
String unmatchedPattern: the witness pattern for the unmatched value
|
|
String suggestedPattern: the suggested pattern for the unmatched value
|
|
problemMessage: "The type '#type' isn't exhaustively matched by the switch cases since it doesn't match the pattern '#unmatchedPattern'."
|
|
correctionMessage: "Try adding a default case or cases that match '#suggestedPattern'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `switch` statement switching
|
|
over an exhaustive type is missing a case for one or more of the possible
|
|
values that could flow through it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the switch statement
|
|
doesn't have a case for the value `E.three`, and `E` is an exhaustive
|
|
type:
|
|
|
|
```dart
|
|
enum E { one, two, three }
|
|
|
|
void f(E e) {
|
|
[!switch!] (e) {
|
|
case E.one:
|
|
case E.two:
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add a case for each of the constants that aren't currently being matched:
|
|
|
|
```dart
|
|
enum E { one, two, three }
|
|
|
|
void f(E e) {
|
|
switch (e) {
|
|
case E.one:
|
|
case E.two:
|
|
break;
|
|
case E.three:
|
|
}
|
|
}
|
|
```
|
|
|
|
If the missing values don't need to be matched, then add a `default`
|
|
clause or a wildcard pattern:
|
|
|
|
```dart
|
|
enum E { one, two, three }
|
|
|
|
void f(E e) {
|
|
switch (e) {
|
|
case E.one:
|
|
case E.two:
|
|
break;
|
|
default:
|
|
}
|
|
}
|
|
```
|
|
|
|
But be aware that adding a `default` clause or wildcard pattern will cause
|
|
any future values of the exhaustive type to also be handled, so you will
|
|
have lost the ability for the compiler to warn you if the `switch` needs
|
|
to be updated.
|
|
nonExhaustiveSwitchStatementPrivate:
|
|
type: compileTimeError
|
|
sharedName: nonExhaustiveSwitchStatement
|
|
parameters:
|
|
Type type: the type of the switch scrutinee
|
|
problemMessage: "The enum '#type' isn't exhaustively matched by the switch cases because some of the enum constants are private."
|
|
correctionMessage: "Try adding a default case."
|
|
hasPublishedDocs: true
|
|
nonFinalFieldInEnum:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Enums can only declare final fields.
|
|
correctionMessage: Try making the field final.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an instance field in an enum
|
|
isn't marked as `final`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `f` isn't a
|
|
final field:
|
|
|
|
```dart
|
|
enum E {
|
|
c;
|
|
|
|
int [!f!] = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field must be defined for the enum, then mark the field as being
|
|
`final`:
|
|
|
|
```dart
|
|
enum E {
|
|
c;
|
|
|
|
final int f = 0;
|
|
}
|
|
```
|
|
|
|
If the field can be removed, then remove it:
|
|
|
|
```dart
|
|
enum E {
|
|
c
|
|
}
|
|
```
|
|
nonGenerativeConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
Element constructor: the non-generative constructor
|
|
problemMessage: "The generative constructor '#constructor' is expected, but a factory was found."
|
|
correctionMessage: Try calling a different constructor of the superclass, or making the called constructor not be a factory constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the initializer list of a
|
|
constructor invokes a constructor from the superclass, and the invoked
|
|
constructor is a factory constructor. Only a generative constructor can be
|
|
invoked in the initializer list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the invocation of the
|
|
constructor `super.one()` is invoking a factory constructor:
|
|
|
|
```dart
|
|
class A {
|
|
factory A.one() = B;
|
|
A.two();
|
|
}
|
|
|
|
class B extends A {
|
|
B() : [!super.one()!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the super invocation to invoke a generative constructor:
|
|
|
|
```dart
|
|
class A {
|
|
factory A.one() = B;
|
|
A.two();
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super.two();
|
|
}
|
|
```
|
|
|
|
If the generative constructor is the unnamed constructor, and if there are
|
|
no arguments being passed to it, then you can remove the super invocation.
|
|
nonGenerativeImplicitConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String superclassName: the name of the superclass
|
|
String className: the name of the current class
|
|
Element factoryConstructor: the implicitly called factory constructor of the superclass
|
|
problemMessage: "The unnamed constructor of superclass '#superclassName' (called by the default constructor of '#className') must be a generative constructor, but factory found."
|
|
correctionMessage: "Try adding an explicit constructor that has a different superinitializer or changing the superclass constructor '#factoryConstructor' to not be a factory constructor."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class has an implicit
|
|
generative constructor and the superclass has an explicit unnamed factory
|
|
constructor. The implicit constructor in the subclass implicitly invokes
|
|
the unnamed constructor in the superclass, but generative constructors can
|
|
only invoke another generative constructor, not a factory constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the implicit
|
|
constructor in `B` invokes the unnamed constructor in `A`, but the
|
|
constructor in `A` is a factory constructor, when a generative constructor
|
|
is required:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() => throw 0;
|
|
A.named();
|
|
}
|
|
|
|
class [!B!] extends A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the unnamed constructor in the superclass can be a generative
|
|
constructor, then change it to be a generative constructor:
|
|
|
|
```dart
|
|
class A {
|
|
A();
|
|
A.named();
|
|
}
|
|
|
|
class B extends A { }
|
|
```
|
|
|
|
If the unnamed constructor can't be a generative constructor and there are
|
|
other generative constructors in the superclass, then explicitly invoke
|
|
one of them:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() => throw 0;
|
|
A.named();
|
|
}
|
|
|
|
class B extends A {
|
|
B() : super.named();
|
|
}
|
|
```
|
|
|
|
If there are no generative constructors that can be used and none can be
|
|
added, then implement the superclass rather than extending it:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() => throw 0;
|
|
A.named();
|
|
}
|
|
|
|
class B implements A {}
|
|
```
|
|
nonSyncFactory:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Factory bodies can't use 'async', 'async*', or 'sync*'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the body of a factory
|
|
constructor is marked with `async`, `async*`, or `sync*`. All constructors,
|
|
including factory constructors, are required to return an instance of the
|
|
class in which they're declared, not a `Future`, `Stream`, or `Iterator`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the body of the factory
|
|
constructor is marked with `async`:
|
|
|
|
```dart
|
|
%ignore=invalid_modifier_on_constructor
|
|
class C {
|
|
factory C() [!async!] {
|
|
return C._();
|
|
}
|
|
C._();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the member must be declared as a factory constructor, then remove the
|
|
keyword appearing before the body:
|
|
|
|
```dart
|
|
class C {
|
|
factory C() {
|
|
return C._();
|
|
}
|
|
C._();
|
|
}
|
|
```
|
|
|
|
If the member must return something other than an instance of the enclosing
|
|
class, then make the member a static method:
|
|
|
|
```dart
|
|
class C {
|
|
static Future<C> m() async {
|
|
return C._();
|
|
}
|
|
C._();
|
|
}
|
|
```
|
|
nonTypeAsTypeArgument:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name appearing where a type is expected
|
|
problemMessage: "The name '#name' isn't a type, so it can't be used as a type argument."
|
|
correctionMessage: "Try correcting the name to an existing type, or defining a type named '#name'."
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an identifier that isn't a type
|
|
is used as a type argument.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` is a variable, not
|
|
a type:
|
|
|
|
```dart
|
|
var x = 0;
|
|
List<[!x!]> xList = [];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the type argument to be a type:
|
|
|
|
```dart
|
|
var x = 0;
|
|
List<int> xList = [];
|
|
```
|
|
nonTypeInCatchClause:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the non-type element
|
|
problemMessage: "The name '#name' isn't a type and can't be used in an on-catch clause."
|
|
correctionMessage: Try correcting the name to match an existing class.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the identifier following the
|
|
`on` in a `catch` clause is defined to be something other than a type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is a function, not
|
|
a type:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} on [!f!] {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the name to the type of object that should be caught:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} on FormatException {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
nonVoidReturnForOperator:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The return type of the operator []= must be 'void'."
|
|
correctionMessage: "Try changing the return type to 'void'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a declaration of the operator
|
|
`[]=` has a return type other than `void`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the declaration of the
|
|
operator `[]=` has a return type of `int`:
|
|
|
|
```dart
|
|
class C {
|
|
[!int!] operator []=(int index, int value) => 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the return type to `void`:
|
|
|
|
```dart
|
|
class C {
|
|
void operator []=(int index, int value) => 0;
|
|
}
|
|
```
|
|
nonVoidReturnForSetter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The return type of the setter must be 'void' or absent."
|
|
correctionMessage: Try removing the return type, or define a method rather than a setter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a setter is defined with a
|
|
return type other than `void`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the setter `p` has a
|
|
return type of `int`:
|
|
|
|
```dart
|
|
class C {
|
|
[!int!] set p(int i) => 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the return type to `void` or omit the return type:
|
|
|
|
```dart
|
|
class C {
|
|
set p(int i) => 0;
|
|
}
|
|
```
|
|
notAssignedPotentiallyNonNullableLocalVariable:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable that is invalid
|
|
problemMessage: "The non-nullable local variable '#name' must be assigned before it can be used."
|
|
correctionMessage: "Try giving it an initializer expression, or ensure that it's assigned on every execution path."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a local variable is referenced
|
|
and has all these characteristics:
|
|
- Has a type that's [potentially non-nullable][].
|
|
- Doesn't have an initializer.
|
|
- Isn't marked as `late`.
|
|
- The analyzer can't prove that the local variable will be assigned before
|
|
the reference based on the specification of [definite assignment][].
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `x` can't have a value
|
|
of `null`, but is referenced before a value was assigned to it:
|
|
|
|
```dart
|
|
String f() {
|
|
int x;
|
|
return [!x!].toString();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the assignment to `x`
|
|
might not be executed, so it might have a value of `null`:
|
|
|
|
```dart
|
|
int g(bool b) {
|
|
int x;
|
|
if (b) {
|
|
x = 1;
|
|
}
|
|
return [!x!] * 2;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the analyzer can't
|
|
prove, based on definite assignment analysis, that `x` won't be referenced
|
|
without having a value assigned to it:
|
|
|
|
```dart
|
|
int h(bool b) {
|
|
int x;
|
|
if (b) {
|
|
x = 1;
|
|
}
|
|
if (b) {
|
|
return [!x!] * 2;
|
|
}
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If `null` is a valid value, then make the variable nullable:
|
|
|
|
```dart
|
|
String f() {
|
|
int? x;
|
|
return x!.toString();
|
|
}
|
|
```
|
|
|
|
If `null` isn't a valid value, and there's a reasonable default value, then
|
|
add an initializer:
|
|
|
|
```dart
|
|
int g(bool b) {
|
|
int x = 2;
|
|
if (b) {
|
|
x = 1;
|
|
}
|
|
return x * 2;
|
|
}
|
|
```
|
|
|
|
Otherwise, ensure that a value was assigned on every possible code path
|
|
before the value is accessed:
|
|
|
|
```dart
|
|
int g(bool b) {
|
|
int x;
|
|
if (b) {
|
|
x = 1;
|
|
} else {
|
|
x = 2;
|
|
}
|
|
return x * 2;
|
|
}
|
|
```
|
|
|
|
You can also mark the variable as `late`, which removes the diagnostic, but
|
|
if the variable isn't assigned a value before it's accessed, then it
|
|
results in an exception being thrown at runtime. This approach should only
|
|
be used if you're sure that the variable will always be assigned, even
|
|
though the analyzer can't prove it based on definite assignment analysis.
|
|
|
|
```dart
|
|
int h(bool b) {
|
|
late int x;
|
|
if (b) {
|
|
x = 1;
|
|
}
|
|
if (b) {
|
|
return x * 2;
|
|
}
|
|
return 0;
|
|
}
|
|
```
|
|
notAType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name that is not a type
|
|
problemMessage: "#name isn't a type."
|
|
correctionMessage: Try correcting the name to match an existing type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name is used as a type but
|
|
declared to be something other than a type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is a function:
|
|
|
|
```dart
|
|
f() {}
|
|
g([!f!] v) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the name with the name of a type.
|
|
notBinaryOperator:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the operator that is not a binary operator.
|
|
problemMessage: "'#name' isn't a binary operator."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an operator that can only be
|
|
used as a unary operator is used as a binary operator.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the operator `~` can
|
|
only be used as a unary operator:
|
|
|
|
```dart
|
|
var a = 5 [!~!] 3;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the operator with the correct binary operator:
|
|
|
|
```dart
|
|
var a = 5 - 3;
|
|
```
|
|
notEnoughPositionalArgumentsSingular:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: notEnoughPositionalArguments
|
|
problemMessage: "1 positional argument expected, but 0 found."
|
|
correctionMessage: Try adding the missing argument.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function invocation
|
|
has fewer positional arguments than the number of required positional
|
|
parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` declares two
|
|
required parameters, but only one argument is provided:
|
|
|
|
```dart
|
|
void f(int a, int b) {}
|
|
void g() {
|
|
f(0[!)!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add arguments corresponding to the remaining parameters:
|
|
|
|
```dart
|
|
void f(int a, int b) {}
|
|
void g() {
|
|
f(0, 1);
|
|
}
|
|
```
|
|
notEnoughPositionalArgumentsPlural:
|
|
type: compileTimeError
|
|
parameters:
|
|
int requiredParameterCount: the expected number of required arguments
|
|
int actualArgumentCount: the actual number of positional arguments given
|
|
sharedName: notEnoughPositionalArguments
|
|
problemMessage: "#requiredParameterCount positional arguments expected, but #actualArgumentCount found."
|
|
correctionMessage: Try adding the missing arguments.
|
|
hasPublishedDocs: true
|
|
notEnoughPositionalArgumentsNameSingular:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: name of the function or method
|
|
sharedName: notEnoughPositionalArguments
|
|
problemMessage: "1 positional argument expected by '#name', but 0 found."
|
|
correctionMessage: Try adding the missing argument.
|
|
hasPublishedDocs: true
|
|
notEnoughPositionalArgumentsNamePlural:
|
|
type: compileTimeError
|
|
parameters:
|
|
int requiredParameterCount: the expected number of required arguments
|
|
int actualArgumentCount: the actual number of positional arguments given
|
|
String name: name of the function or method
|
|
sharedName: notEnoughPositionalArguments
|
|
problemMessage: "#requiredParameterCount positional arguments expected by '#name', but #actualArgumentCount found."
|
|
correctionMessage: Try adding the missing arguments.
|
|
hasPublishedDocs: true
|
|
notInitializedNonNullableInstanceField:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the field that is not initialized
|
|
problemMessage: "Non-nullable instance field '#name' must be initialized."
|
|
correctionMessage: "Try adding an initializer expression, or a generative constructor that initializes it, or mark it 'late'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field is declared and has all
|
|
these characteristics:
|
|
- Has a type that's [potentially non-nullable][]
|
|
- Doesn't have an initializer
|
|
- Isn't marked as `late`
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `x` is implicitly
|
|
initialized to `null` when it isn't allowed to be `null`:
|
|
|
|
```dart
|
|
class C {
|
|
int [!x!];
|
|
}
|
|
```
|
|
|
|
Similarly, the following code produces this diagnostic because `x` is
|
|
implicitly initialized to `null`, when it isn't allowed to be `null`, by
|
|
one of the constructors, even though it's initialized by other
|
|
constructors:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
|
|
C(this.x);
|
|
|
|
[!C.n!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a reasonable default value for the field that's the same for all
|
|
instances, then add an initializer expression:
|
|
|
|
```dart
|
|
class C {
|
|
int x = 0;
|
|
}
|
|
```
|
|
|
|
If the value of the field should be provided when an instance is created,
|
|
then add a constructor that sets the value of the field or update an
|
|
existing constructor:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
|
|
C(this.x);
|
|
}
|
|
```
|
|
|
|
You can also mark the field as `late`, which removes the diagnostic, but if
|
|
the field isn't assigned a value before it's accessed, then it results in
|
|
an exception being thrown at runtime. This approach should only be used if
|
|
you're sure that the field will always be assigned before it's referenced.
|
|
|
|
```dart
|
|
class C {
|
|
late int x;
|
|
}
|
|
```
|
|
notInitializedNonNullableInstanceFieldConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the field that is not initialized
|
|
sharedName: notInitializedNonNullableInstanceField
|
|
problemMessage: "Non-nullable instance field '#name' must be initialized."
|
|
correctionMessage: "Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'."
|
|
hasPublishedDocs: true
|
|
notInitializedNonNullableVariable:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable that is invalid
|
|
problemMessage: "The non-nullable variable '#name' must be initialized."
|
|
correctionMessage: Try adding an initializer expression.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a static field or top-level
|
|
variable has a type that's non-nullable and doesn't have an initializer.
|
|
Fields and variables that don't have an initializer are normally
|
|
initialized to `null`, but the type of the field or variable doesn't allow
|
|
it to be set to `null`, so an explicit initializer must be provided.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the field `f` can't be
|
|
initialized to `null`:
|
|
|
|
```dart
|
|
class C {
|
|
static int [!f!];
|
|
}
|
|
```
|
|
|
|
Similarly, the following code produces this diagnostic because the
|
|
top-level variable `v` can't be initialized to `null`:
|
|
|
|
```dart
|
|
int [!v!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the field or variable can't be initialized to `null`, then add an
|
|
initializer that sets it to a non-null value:
|
|
|
|
```dart
|
|
class C {
|
|
static int f = 0;
|
|
}
|
|
```
|
|
|
|
If the field or variable should be initialized to `null`, then change the
|
|
type to be nullable:
|
|
|
|
```dart
|
|
int? v;
|
|
```
|
|
|
|
If the field or variable can't be initialized in the declaration but will
|
|
always be initialized before it's referenced, then mark it as being `late`:
|
|
|
|
```dart
|
|
class C {
|
|
static late int f;
|
|
}
|
|
```
|
|
notInstantiatedBound:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Type parameter bound types must be instantiated.
|
|
correctionMessage: Try adding type arguments to the type parameter bound.
|
|
hasPublishedDocs: false
|
|
notIterableSpread:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Spread elements in list or set literals must implement 'Iterable'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the static type of the
|
|
expression of a spread element that appears in either a list literal or a
|
|
set literal doesn't implement the type `Iterable`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
var m = <String, int>{'a': 0, 'b': 1};
|
|
var s = <String>{...[!m!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
The most common fix is to replace the expression with one that produces an
|
|
iterable object:
|
|
|
|
```dart
|
|
var m = <String, int>{'a': 0, 'b': 1};
|
|
var s = <String>{...m.keys};
|
|
```
|
|
notMapSpread:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Spread elements in map literals must implement 'Map'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the static type of the
|
|
expression of a spread element that appears in a map literal doesn't
|
|
implement the type `Map`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `l` isn't a `Map`:
|
|
|
|
```dart
|
|
var l = <String>['a', 'b'];
|
|
var m = <int, String>{...[!l!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
The most common fix is to replace the expression with one that produces a
|
|
map:
|
|
|
|
```dart
|
|
var l = <String>['a', 'b'];
|
|
var m = <int, String>{...l.asMap()};
|
|
```
|
|
notNullAwareNullSpread:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The Null-typed expression can't be used with a non-null-aware spread."
|
|
hasPublishedDocs: false
|
|
noAnnotationConstructorArguments:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Annotation creation must have arguments.
|
|
correctionMessage: Try adding an empty argument list.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an annotation consists of a
|
|
single identifier, but that identifier is the name of a class rather than a
|
|
variable. To create an instance of the class, the identifier must be
|
|
followed by an argument list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `C` is a class, and a
|
|
class can't be used as an annotation without invoking a `const` constructor
|
|
from the class:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
}
|
|
|
|
[!@C!]
|
|
var x;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the missing argument list:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
}
|
|
|
|
@C()
|
|
var x;
|
|
```
|
|
noCombinedSuperSignature:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class where override error was detected
|
|
String candidateSignatures: the list of candidate signatures which cannot be combined
|
|
problemMessage: "Can't infer missing types in '#className' from overridden methods: #candidateSignatures."
|
|
correctionMessage: "Try providing explicit types for this method's parameters and return type."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there is a method declaration
|
|
for which one or more types needs to be inferred, and those types can't be
|
|
inferred because none of the overridden methods has a function type that is
|
|
a supertype of all the other overridden methods, as specified by
|
|
[override inference][].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `m` declared
|
|
in the class `C` is missing both the return type and the type of the
|
|
parameter `a`, and neither of the missing types can be inferred for it:
|
|
|
|
```dart
|
|
abstract class A {
|
|
A m(String a);
|
|
}
|
|
|
|
abstract class B {
|
|
B m(int a);
|
|
}
|
|
|
|
abstract class C implements A, B {
|
|
[!m!](a);
|
|
}
|
|
```
|
|
|
|
In this example, override inference can't be performed because the
|
|
overridden methods are incompatible in these ways:
|
|
- Neither parameter type (`String` and `int`) is a supertype of the other.
|
|
- Neither return type is a subtype of the other.
|
|
|
|
#### Common fixes
|
|
|
|
If possible, add types to the method in the subclass that are consistent
|
|
with the types from all the overridden methods:
|
|
|
|
```dart
|
|
abstract class A {
|
|
A m(String a);
|
|
}
|
|
|
|
abstract class B {
|
|
B m(int a);
|
|
}
|
|
|
|
abstract class C implements A, B {
|
|
C m(Object a);
|
|
}
|
|
```
|
|
noDefaultSuperConstructorExplicit:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type supertype: the supertype that does not define an implicitly invoked constructor
|
|
sharedName: noDefaultSuperConstructor
|
|
problemMessage: "The superclass '#supertype' doesn't have a zero argument constructor."
|
|
correctionMessage: "Try declaring a zero argument constructor in '#supertype', or explicitly invoking a different constructor in '#supertype'."
|
|
hasPublishedDocs: false
|
|
noDefaultSuperConstructorImplicit:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type superclassType: the name of the superclass that does not define an implicitly invoked constructor
|
|
String subclassName: the name of the subclass that does not contain any explicit constructors
|
|
sharedName: noDefaultSuperConstructor
|
|
problemMessage: "The superclass '#superclassType' doesn't have a zero argument constructor."
|
|
correctionMessage: "Try declaring a zero argument constructor in '#superclassType', or declaring a constructor in #subclassName that explicitly invokes a constructor in '#superclassType'."
|
|
hasPublishedDocs: false
|
|
noGenerativeConstructorsInSuperclass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the superclass
|
|
problemMessage: "The class '#subclassName' can't extend '#superclassName' because '#superclassName' only has factory constructors (no generative constructors), and '#subclassName' has at least one generative constructor."
|
|
correctionMessage: "Try implementing the class instead, adding a generative (not factory) constructor to the superclass '#superclassName', or a factory constructor to the subclass."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that has at least one
|
|
generative constructor (whether explicit or implicit) has a superclass
|
|
that doesn't have any generative constructors. Every generative
|
|
constructor, except the one defined in `Object`, invokes, either
|
|
explicitly or implicitly, one of the generative constructors from its
|
|
superclass.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B` has an
|
|
implicit generative constructor that can't invoke a generative constructor
|
|
from `A` because `A` doesn't have any generative constructors:
|
|
|
|
```dart
|
|
class A {
|
|
factory A.none() => throw '';
|
|
}
|
|
|
|
class B extends [!A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the superclass should have a generative constructor, then add one:
|
|
|
|
```dart
|
|
class A {
|
|
A();
|
|
factory A.none() => throw '';
|
|
}
|
|
|
|
class B extends A {}
|
|
```
|
|
|
|
If the subclass shouldn't have a generative constructor, then remove it by
|
|
adding a factory constructor:
|
|
|
|
```dart
|
|
class A {
|
|
factory A.none() => throw '';
|
|
}
|
|
|
|
class B extends A {
|
|
factory B.none() => throw '';
|
|
}
|
|
```
|
|
|
|
If the subclass must have a generative constructor but the superclass
|
|
can't have one, then implement the superclass instead:
|
|
|
|
```dart
|
|
class A {
|
|
factory A.none() => throw '';
|
|
}
|
|
|
|
class B implements A {}
|
|
```
|
|
nullableTypeInExtendsClause:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Nullable types can't be extended."
|
|
correctionMessage: Try removing the question mark.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class declaration uses an
|
|
`extends` clause to specify a superclass, and the superclass is followed by
|
|
a `?`.
|
|
|
|
It isn't valid to specify a nullable superclass because doing so would have
|
|
no meaning; it wouldn't change either the interface or implementation being
|
|
inherited by the class containing the `extends` clause.
|
|
|
|
Note, however, that it _is_ valid to use a nullable type as a type argument
|
|
to the superclass, such as `class A extends B<C?> {}`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A?` is a nullable
|
|
type, and nullable types can't be used in an `extends` clause:
|
|
|
|
```dart
|
|
class A {}
|
|
class B extends [!A?!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the question mark from the type:
|
|
|
|
```dart
|
|
class A {}
|
|
class B extends A {}
|
|
```
|
|
nullableTypeInImplementsClause:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Nullable types can't be implemented."
|
|
correctionMessage: Try removing the question mark.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class, enum, mixin, or
|
|
extension type declaration has an `implements` clause, and an
|
|
interface is followed by a `?`.
|
|
|
|
It isn't valid to specify a nullable interface because doing so would have
|
|
no meaning; it wouldn't change the interface being inherited by the class
|
|
containing the `implements` clause.
|
|
|
|
Note, however, that it _is_ valid to use a nullable type as a type argument
|
|
to the interface, such as `class A implements B<C?> {}`.
|
|
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A?` is a nullable
|
|
type, and nullable types can't be used in an `implements` clause:
|
|
|
|
```dart
|
|
class A {}
|
|
class B implements [!A?!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the question mark from the type:
|
|
|
|
```dart
|
|
class A {}
|
|
class B implements A {}
|
|
```
|
|
nullableTypeInOnClause:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Nullable types can't be used as a superclass constraint."
|
|
correctionMessage: Try removing the question mark.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin declaration uses an `on`
|
|
clause to specify a superclass constraint, and the class that's specified
|
|
is followed by a `?`.
|
|
|
|
It isn't valid to specify a nullable superclass constraint because doing so
|
|
would have no meaning; it wouldn't change the interface being depended on
|
|
by the mixin containing the `on` clause.
|
|
|
|
Note, however, that it _is_ valid to use a nullable type as a type argument
|
|
to the superclass constraint, such as `mixin A on B<C?> {}`.
|
|
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A?` is a nullable type
|
|
and nullable types can't be used in an `on` clause:
|
|
|
|
```dart
|
|
class C {}
|
|
mixin M on [!C?!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the question mark from the type:
|
|
|
|
```dart
|
|
class C {}
|
|
mixin M on C {}
|
|
```
|
|
nullableTypeInWithClause:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Nullable types can't be mixed in."
|
|
correctionMessage: Try removing the question mark.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class or mixin declaration has
|
|
a `with` clause, and a mixin is followed by a `?`.
|
|
|
|
It isn't valid to specify a nullable mixin because doing so would have no
|
|
meaning; it wouldn't change either the interface or implementation being
|
|
inherited by the class containing the `with` clause.
|
|
|
|
Note, however, that it _is_ valid to use a nullable type as a type argument
|
|
to the mixin, such as `class A with B<C?> {}`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A?` is a nullable
|
|
type, and nullable types can't be used in a `with` clause:
|
|
|
|
```dart
|
|
mixin M {}
|
|
class C with [!M?!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the question mark from the type:
|
|
|
|
```dart
|
|
mixin M {}
|
|
class C with M {}
|
|
```
|
|
objectCannotExtendAnotherClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The class 'Object' can't extend any other class."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
7.9 Superclasses: It is a compile-time error to specify an extends clause
|
|
for class Object.
|
|
obsoleteColonForDefaultValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Using a colon as the separator before a default value is no longer supported.
|
|
correctionMessage: Try replacing the colon with an equal sign.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a colon (`:`) is used as the
|
|
separator before the default value of an optional named parameter.
|
|
While this syntax used to be allowed, it was removed in favor of
|
|
using an equal sign (`=`).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because a colon is being used
|
|
before the default value of the optional parameter `i`:
|
|
|
|
```dart
|
|
void f({int i [!:!] 0}) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the colon with an equal sign:
|
|
|
|
```dart
|
|
void f({int i = 0}) {}
|
|
```
|
|
onRepeated:
|
|
type: compileTimeError
|
|
parameters:
|
|
String interfaceName: the name of the interface that is implemented more than once
|
|
problemMessage: "The type '#interfaceName' can be included in the superclass constraints only once."
|
|
correctionMessage: Try removing all except one occurrence of the type name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the same type is listed in the
|
|
superclass constraints of a mixin multiple times.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A` is included twice
|
|
in the superclass constraints for `M`:
|
|
|
|
```dart
|
|
mixin M on A, [!A!] {
|
|
}
|
|
|
|
class A {}
|
|
class B {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a different type should be included in the superclass constraints, then
|
|
replace one of the occurrences with the other type:
|
|
|
|
```dart
|
|
mixin M on A, B {
|
|
}
|
|
|
|
class A {}
|
|
class B {}
|
|
```
|
|
|
|
If no other type was intended, then remove the repeated type name:
|
|
|
|
```dart
|
|
mixin M on A {
|
|
}
|
|
|
|
class A {}
|
|
class B {}
|
|
```
|
|
optionalParameterInOperator:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Optional parameters aren't allowed when defining an operator."
|
|
correctionMessage: Try removing the optional parameters.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when one or more of the parameters in
|
|
an operator declaration are optional.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the parameter `other`
|
|
is an optional parameter:
|
|
|
|
```dart
|
|
class C {
|
|
C operator +([[!C? other!]]) => this;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Make all of the parameters be required parameters:
|
|
|
|
```dart
|
|
class C {
|
|
C operator +(C other) => this;
|
|
}
|
|
```
|
|
partOfDifferentLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String expectedName: the name of expected library name
|
|
String actualName: the non-matching actual library name from the "part of" declaration
|
|
problemMessage: "Expected this library to be part of '#expectedName', not '#actualName'."
|
|
correctionMessage: "Try including a different part, or changing the name of the library in the part's part-of directive."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library attempts to include a
|
|
file as a part of itself when the other file is a part of a different
|
|
library.
|
|
|
|
#### Example
|
|
|
|
Given a file `part.dart` containing
|
|
|
|
```dart
|
|
%uri="package:a/part.dart"
|
|
part of 'library.dart';
|
|
```
|
|
|
|
The following code, in any file other than `library.dart`, produces this
|
|
diagnostic because it attempts to include `part.dart` as a part of itself
|
|
when `part.dart` is a part of a different library:
|
|
|
|
```dart
|
|
part [!'package:a/part.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the library should be using a different file as a part, then change the
|
|
URI in the part directive to be the URI of the other file.
|
|
|
|
If the [part file][] should be a part of this library, then update the URI
|
|
(or library name) in the part-of directive to be the URI (or name) of the
|
|
correct library.
|
|
partOfNonPart:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uriStr: the URI pointing to a non-library declaration
|
|
problemMessage: "The included part '#uriStr' must have a part-of directive."
|
|
correctionMessage: "Try adding a part-of directive to '#uriStr'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a part directive is found and
|
|
the referenced file doesn't have a part-of directive.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` containing:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
class A {}
|
|
```
|
|
|
|
The following code produces this diagnostic because `a.dart` doesn't
|
|
contain a part-of directive:
|
|
|
|
```dart
|
|
part [!'a.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the referenced file is intended to be a part of another library, then
|
|
add a part-of directive to the file:
|
|
|
|
```dart
|
|
part of 'test.dart';
|
|
|
|
class A {}
|
|
```
|
|
|
|
If the referenced file is intended to be a library, then replace the part
|
|
directive with an import directive:
|
|
|
|
```dart
|
|
%ignore=unused_import
|
|
import 'a.dart';
|
|
```
|
|
partOfUnnamedLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String libraryName: the non-matching actual library name from the "part of" declaration
|
|
problemMessage: "The library is unnamed. A URI is expected, not a library name '#libraryName', in the part-of directive."
|
|
correctionMessage: Try changing the part-of directive to a URI, or try including a different part.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library that doesn't have a
|
|
`library` directive (and hence has no name) contains a `part` directive
|
|
and the `part of` directive in the [part file][] uses a name to specify
|
|
the library that it's a part of.
|
|
|
|
#### Example
|
|
|
|
Given a [part file][] named `part_file.dart` containing the following
|
|
code:
|
|
|
|
```dart
|
|
%language=3.4
|
|
%uri="lib/part_file.dart"
|
|
part of lib;
|
|
```
|
|
|
|
The following code produces this diagnostic because the library including
|
|
the [part file][] doesn't have a name even though the [part file][] uses a
|
|
name to specify which library it's a part of:
|
|
|
|
```dart
|
|
%language=3.4
|
|
part [!'part_file.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the `part of` directive in the [part file][] to specify its library
|
|
by URI:
|
|
|
|
```dart
|
|
%language=3.4
|
|
%uri="lib/part_file.dart"
|
|
part of 'test.dart';
|
|
```
|
|
patternAssignmentNotLocalVariable:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Only local variables can be assigned in pattern assignments.
|
|
correctionMessage: Try assigning to a local variable.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a pattern assignment assigns a
|
|
value to anything other than a local variable. Patterns can't assign to
|
|
fields or top-level variables.
|
|
|
|
#### Example
|
|
|
|
If the code is cleaner when destructuring with a pattern, then rewrite the
|
|
code to assign the value to a local variable in a pattern declaration,
|
|
assigning the non-local variable separately:
|
|
|
|
```dart
|
|
class C {
|
|
var x = 0;
|
|
|
|
void f((int, int) r) {
|
|
([!x!], _) = r;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the code is cleaner when using a pattern assignment, then rewrite the
|
|
code to assign the value to a local variable, assigning the non-local
|
|
variable separately:
|
|
|
|
```dart
|
|
class C {
|
|
var x = 0;
|
|
|
|
void f((int, int) r) {
|
|
var (a, _) = r;
|
|
x = a;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the code is cleaner without using a pattern assignment, then rewrite
|
|
the code to not use a pattern assignment:
|
|
|
|
```dart
|
|
class C {
|
|
var x = 0;
|
|
|
|
void f((int, int) r) {
|
|
x = r.$1;
|
|
}
|
|
}
|
|
```
|
|
patternTypeMismatchInIrrefutableContext:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type matchedType: the matched type
|
|
Type requiredType: the required type
|
|
problemMessage: "The matched value of type '#matchedType' isn't assignable to the required type '#requiredType'."
|
|
correctionMessage: "Try changing the required type of the pattern, or the matched value type."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of the value on the
|
|
right-hand side of a pattern assignment or pattern declaration doesn't
|
|
match the type required by the pattern being used to match it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` might not be a
|
|
`String` and hence might not match the object pattern:
|
|
|
|
```dart
|
|
void f(Object x) {
|
|
var [!String(length: a)!] = x;
|
|
print(a);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the code so that the type of the expression on the right-hand side
|
|
matches the type required by the pattern:
|
|
|
|
```dart
|
|
void f(String x) {
|
|
var String(length: a) = x;
|
|
print(a);
|
|
}
|
|
```
|
|
patternVariableAssignmentInsideGuard:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Pattern variables can't be assigned inside the guard of the enclosing guarded pattern.
|
|
correctionMessage: Try assigning to a different variable.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a pattern variable is assigned
|
|
a value inside a guard (`when`) clause.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the variable `a` is
|
|
assigned a value inside the guard clause:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var a when ([!a!] = 1) > 0) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a value you need to capture, then assign it to a different
|
|
variable:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
var b;
|
|
if (x case var a when (b = 1) > 0) {
|
|
print(a + b);
|
|
}
|
|
}
|
|
```
|
|
|
|
If there isn't a value you need to capture, then remove the assignment:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var a when 1 > 0) {
|
|
print(a);
|
|
}
|
|
}
|
|
```
|
|
patternVariableSharedCaseScopeDifferentFinalityOrType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the pattern variable
|
|
sharedName: invalidPatternVariableInSharedCaseScope
|
|
problemMessage: "The variable '#name' doesn't have the same type and/or finality in all cases that share this body."
|
|
correctionMessage: Try declaring the variable pattern with the same type and finality in all cases.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when multiple case clauses in a
|
|
switch statement share a body, and at least one of them declares a
|
|
variable that is referenced in the shared statements, but the variable is
|
|
either not declared in all of the case clauses or it is declared in
|
|
inconsistent ways.
|
|
|
|
If the variable isn't declared in all of the case clauses, then it won't
|
|
have a value if one of the clauses that doesn't declare the variable is
|
|
the one that matches and executes the body. This includes the situation
|
|
where one of the case clauses is the `default` clause.
|
|
|
|
If the variable is declared in inconsistent ways, either being `final` in
|
|
some cases and not `final` in others or having a different type in
|
|
different cases, then the semantics of what the type or finality of the
|
|
variable should be are not defined.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the variable `a` is
|
|
only declared in one of the case clauses, and won't have a value if the
|
|
second clause is the one that matched `x`:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case int a when a > 0:
|
|
case 0:
|
|
[!a!];
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the variable `a` isn't
|
|
declared in the `default` clause, and won't have a value if the body is
|
|
executed because none of the other clauses matched `x`:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case int a when a > 0:
|
|
default:
|
|
[!a!];
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the variable `a` won't
|
|
have a value if the body is executed because a different group of cases
|
|
caused control to continue at the label:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
someLabel:
|
|
case int a when a > 0:
|
|
[!a!];
|
|
case int b when b < 0:
|
|
continue someLabel;
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the variable `a`,
|
|
while being assigned in all of the case clauses, doesn't have then same
|
|
type associated with it in every clause:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case int a when a < 0:
|
|
case num a when a > 0:
|
|
[!a!];
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the variable `a` is
|
|
`final` in the first case clause and isn't `final` in the second case
|
|
clause:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case final int a when a < 0:
|
|
case int a when a > 0:
|
|
[!a!];
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the variable isn't declared in all of the cases, and you need to
|
|
reference it in the statements, then declare it in the other cases:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case int a when a > 0:
|
|
case int a when a == 0:
|
|
a;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the variable isn't declared in all of the cases, and you don't need to
|
|
reference it in the statements, then remove the references to it and
|
|
remove the declarations from the other cases:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
switch (x) {
|
|
case > 0:
|
|
case 0:
|
|
}
|
|
}
|
|
```
|
|
|
|
If the type of the variable is different, decide the type the variable
|
|
should have and make the cases consistent:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case num a when a < 0:
|
|
case num a when a > 0:
|
|
a;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the finality of the variable is different, decide whether it should be
|
|
`final` or not `final` and make the cases consistent:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
switch (x) {
|
|
case final int a when a < 0:
|
|
case final int a when a > 0:
|
|
a;
|
|
}
|
|
}
|
|
```
|
|
patternVariableSharedCaseScopeHasLabel:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the pattern variable
|
|
sharedName: invalidPatternVariableInSharedCaseScope
|
|
problemMessage: "The variable '#name' is not available because there is a label or 'default' case."
|
|
correctionMessage: Try removing the label, or providing the 'default' case with its own body.
|
|
hasPublishedDocs: true
|
|
patternVariableSharedCaseScopeNotAllCases:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the pattern variable
|
|
sharedName: invalidPatternVariableInSharedCaseScope
|
|
problemMessage: "The variable '#name' is available in some, but not all cases that share this body."
|
|
correctionMessage: Try declaring the variable pattern with the same type and finality in all cases.
|
|
hasPublishedDocs: true
|
|
positionalFieldInObjectPattern:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Object patterns can only use named fields.
|
|
correctionMessage: Try specifying the field name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an object pattern contains a
|
|
field without specifying the getter name. Object pattern fields match
|
|
against values that the object's getters return. Without a getter name
|
|
specified, the pattern field can't access a value to attempt to match against.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the object pattern
|
|
`String(1)` doesn't specify which getter of `String` to access and compare
|
|
with the value `1`:
|
|
|
|
```dart
|
|
void f(Object o) {
|
|
if (o case String([!1!])) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the getter name to access the value, followed
|
|
by a colon before the pattern to match against:
|
|
|
|
```dart
|
|
void f(Object o) {
|
|
if (o case String(length: 1)) {}
|
|
}
|
|
```
|
|
positionalSuperFormalParameterWithPositionalArgument:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Positional super parameters can't be used when the super constructor invocation has a positional argument.
|
|
correctionMessage: Try making all the positional parameters passed to the super constructor be either all super parameters or all normal parameters.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when some, but not all, of the
|
|
positional parameters provided to the constructor of the superclass are
|
|
using a super parameter.
|
|
|
|
Positional super parameters are associated with positional parameters in
|
|
the super constructor by their index. That is, the first super parameter
|
|
is associated with the first positional parameter in the super
|
|
constructor, the second with the second, and so on. The same is true for
|
|
positional arguments. Having both positional super parameters and
|
|
positional arguments means that there are two values associated with the
|
|
same parameter in the superclass's constructor, and hence isn't allowed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor
|
|
`B.new` is using a super parameter to pass one of the required positional
|
|
parameters to the super constructor in `A`, but is explicitly passing the
|
|
other in the super constructor invocation:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x, int y);
|
|
}
|
|
|
|
class B extends A {
|
|
B(int x, super.[!y!]) : super(x);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If all the positional parameters can be super parameters, then convert the
|
|
normal positional parameters to be super parameters:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x, int y);
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.x, super.y);
|
|
}
|
|
```
|
|
|
|
If some positional parameters can't be super parameters, then convert the
|
|
super parameters to be normal parameters:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x, int y);
|
|
}
|
|
|
|
class B extends A {
|
|
B(int x, int y) : super(x, y);
|
|
}
|
|
```
|
|
prefixCollidesWithTopLevelMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the prefix
|
|
problemMessage: "The name '#name' is already used as an import prefix and can't be used to name a top-level element."
|
|
correctionMessage: Try renaming either the top-level element or the prefix.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name is used as both an import
|
|
prefix and the name of a top-level declaration in the same library.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is used as both an
|
|
import prefix and the name of a function:
|
|
|
|
```dart
|
|
%ignore=undefined_method,unused_import
|
|
import 'dart:math' as [!f!];
|
|
|
|
int f() => f.min(0, 1);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to use the name for the import prefix, then rename the
|
|
top-level declaration:
|
|
|
|
```dart
|
|
import 'dart:math' as f;
|
|
|
|
int g() => f.min(0, 1);
|
|
```
|
|
|
|
If you want to use the name for the top-level declaration, then rename the
|
|
import prefix:
|
|
|
|
```dart
|
|
import 'dart:math' as math;
|
|
|
|
int f() => math.min(0, 1);
|
|
```
|
|
prefixIdentifierNotFollowedByDot:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the prefix
|
|
problemMessage: "The name '#name' refers to an import prefix, so it must be followed by '.'."
|
|
correctionMessage: Try correcting the name to refer to something other than a prefix, or renaming the prefix.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import prefix is used by
|
|
itself, without accessing any of the names declared in the libraries
|
|
associated with the prefix. Prefixes aren't variables, and therefore can't
|
|
be used as a value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the prefix `math` is
|
|
being used as if it were a variable:
|
|
|
|
```dart
|
|
import 'dart:math' as math;
|
|
|
|
void f() {
|
|
print([!math!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the code is incomplete, then reference something in one of the libraries
|
|
associated with the prefix:
|
|
|
|
```dart
|
|
import 'dart:math' as math;
|
|
|
|
void f() {
|
|
print(math.pi);
|
|
}
|
|
```
|
|
|
|
If the name is wrong, then correct the name.
|
|
prefixShadowedByLocalDeclaration:
|
|
type: compileTimeError
|
|
parameters:
|
|
String prefix: the prefix being shadowed
|
|
problemMessage: "The prefix '#prefix' can't be used here because it's shadowed by a local declaration."
|
|
correctionMessage: Try renaming either the prefix or the local declaration.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import prefix is used in a
|
|
context where it isn't visible because it was shadowed by a local
|
|
declaration.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the prefix `a` is
|
|
being used to access the class `Future`, but isn't visible because it's
|
|
shadowed by the parameter `a`:
|
|
|
|
```dart
|
|
import 'dart:async' as a;
|
|
|
|
a.Future? f(int a) {
|
|
[!a!].Future? x;
|
|
return x;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename either the prefix:
|
|
|
|
```dart
|
|
import 'dart:async' as p;
|
|
|
|
p.Future? f(int a) {
|
|
p.Future? x;
|
|
return x;
|
|
}
|
|
```
|
|
|
|
Or rename the local variable:
|
|
|
|
```dart
|
|
import 'dart:async' as a;
|
|
|
|
a.Future? f(int p) {
|
|
a.Future? x;
|
|
return x;
|
|
}
|
|
```
|
|
|
|
primaryConstructorBodyWithExpressionBody:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A primary constructor body can't use '=>'."
|
|
correctionMessage: "Try using a block body."
|
|
hasPublishedDocs: false
|
|
|
|
primaryConstructorCannotRedirect:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A primary constructor can't be a redirecting constructor."
|
|
correctionMessage: "Try removing the redirect."
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a primary constructor redirects
|
|
to another constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the primary
|
|
constructor has a redirect to the constructor `C.named`:
|
|
|
|
```dart
|
|
class C(int x) {
|
|
C.named() : this(0);
|
|
this : assert(x > 0), [!this!].named();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the redirection isn't necessary, then remove it:
|
|
|
|
```dart
|
|
class C(int x) {
|
|
C.named() : this(0);
|
|
this : assert(x > 0);
|
|
}
|
|
```
|
|
|
|
If the redirection is necessary, then convert the primary constructor into
|
|
a secondary constructor, and rework other constructors as necessary:
|
|
|
|
```dart
|
|
class C {
|
|
C.named();
|
|
C(int x) : this.named();
|
|
}
|
|
```
|
|
privateCollisionInMixinApplication:
|
|
type: compileTimeError
|
|
parameters:
|
|
String collidingName: the private name that collides
|
|
String mixin1: the name of the first mixin
|
|
String mixin2: the name of the second mixin
|
|
problemMessage: "The private name '#collidingName', defined by '#mixin1', conflicts with the same name defined by '#mixin2'."
|
|
correctionMessage: "Try removing '#mixin1' from the 'with' clause."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when two mixins that define the same
|
|
private member are used together in a single class in a library other than
|
|
the one that defines the mixins.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` containing the following code:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
mixin A {
|
|
void _foo() {}
|
|
}
|
|
|
|
mixin B {
|
|
void _foo() {}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the mixins `A` and `B`
|
|
both define the method `_foo`:
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
class C extends Object with A, [!B!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need both of the mixins, then remove one of them from the
|
|
`with` clause:
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
class C extends Object with A, [!B!] {}
|
|
```
|
|
|
|
If you need both of the mixins, then rename the conflicting member in one
|
|
of the two mixins.
|
|
privateNamedParameterDuplicatePublicName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the corresponding public name of private named parameter
|
|
problemMessage: "The corresponding public name '#name' is already the name of another parameter."
|
|
correctionMessage: "Try renaming one of the parameters."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a private named parameter
|
|
(leading `_`) has a corresponding public name that conflicts with an
|
|
existing parameter name in the same parameter list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the private named
|
|
parameter `_x`'s public name is `x`, which conflicts with the existing
|
|
parameter named `x`:
|
|
|
|
```dart
|
|
class C {
|
|
int? _x;
|
|
C({int? x, this.[!_x!]});
|
|
int? get x => _x;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename one of the two parameters.
|
|
privateNamedParameterWithoutPublicName:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A private named parameter must be a public identifier after removing the leading underscore."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the name of a named parameter
|
|
starts with an underscore and the result of removing the underscore isn't
|
|
a valid public identifier.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the named parameter
|
|
`_2legit` without the `_` is `2legit`, which isn't a valid public
|
|
identifier:
|
|
|
|
```dart
|
|
class C {
|
|
final int? _2legit;
|
|
C({this.[!_2legit!] = 0});
|
|
int? get twoLegit => _2legit;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename the parameter so that the character following the leading
|
|
underscore is a letter.
|
|
privateSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the setter
|
|
problemMessage: "The setter '#name' is private and can't be accessed outside the library that declares it."
|
|
correctionMessage: Try making it public.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a private setter is used in a
|
|
library where it isn't visible.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
class A {
|
|
static int _f = 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because it references the
|
|
private setter `_f` even though the setter isn't visible:
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
void f() {
|
|
A.[!_f!] = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're able to make the setter public, then do so:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
class A {
|
|
static int f = 0;
|
|
}
|
|
```
|
|
|
|
If you aren't able to make the setter public, then find a different way to
|
|
implement the code.
|
|
readPotentiallyUnassignedFinal:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable
|
|
problemMessage: "The final variable '#name' can't be read because it's potentially unassigned at this point."
|
|
correctionMessage: Ensure that it is assigned on necessary execution paths.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a final local variable that
|
|
isn't initialized at the declaration site is read at a point where the
|
|
compiler can't prove that the variable is always initialized before it's
|
|
referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the final local
|
|
variable `x` is read (on line 3) when it's possible that it hasn't yet
|
|
been initialized:
|
|
|
|
```dart
|
|
int f() {
|
|
final int x;
|
|
return [!x!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Ensure that the variable has been initialized before it's read:
|
|
|
|
```dart
|
|
int f(bool b) {
|
|
final int x;
|
|
if (b) {
|
|
x = 0;
|
|
} else {
|
|
x = 1;
|
|
}
|
|
return x;
|
|
}
|
|
```
|
|
recursiveCompileTimeConstant:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The compile-time constant expression depends on itself.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of a compile-time
|
|
constant is defined in terms of itself, either directly or indirectly,
|
|
creating an infinite loop.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic twice because both of the
|
|
constants are defined in terms of the other:
|
|
|
|
```dart
|
|
const [!secondsPerHour!] = minutesPerHour * 60;
|
|
const [!minutesPerHour!] = secondsPerHour / 60;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Break the cycle by finding an alternative way of defining at least one of
|
|
the constants:
|
|
|
|
```dart
|
|
const secondsPerHour = minutesPerHour * 60;
|
|
const minutesPerHour = 60;
|
|
```
|
|
recursiveConstantConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The constant constructor depends on itself."
|
|
hasPublishedDocs: false
|
|
recursiveConstructorRedirect:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constructors can't redirect to themselves either directly or indirectly."
|
|
correctionMessage: Try changing one of the constructors in the loop to not redirect.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
TODO(scheglov): review this later, there are no explicit "it is a
|
|
compile-time error" in specification. But it was added to the co19 and
|
|
there is same error for factories.
|
|
|
|
https://code.google.com/p/dart/issues/detail?id=954
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor redirects to
|
|
itself, either directly or indirectly, creating an infinite loop.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the generative
|
|
constructors `C.a` and `C.b` each redirect to the other:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : [!this.b()!];
|
|
C.b() : [!this.a()!];
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the factory
|
|
constructors `A` and `B` each redirect to the other:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A() = [!B!];
|
|
}
|
|
class B implements A {
|
|
factory B() = [!A!];
|
|
B.named();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
In the case of generative constructors, break the cycle by finding defining
|
|
at least one of the constructors to not redirect to another constructor:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : this.b();
|
|
C.b();
|
|
}
|
|
```
|
|
|
|
In the case of factory constructors, break the cycle by defining at least
|
|
one of the factory constructors to do one of the following:
|
|
|
|
- Redirect to a generative constructor:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A() = B;
|
|
}
|
|
class B implements A {
|
|
factory B() = B.named;
|
|
B.named();
|
|
}
|
|
```
|
|
|
|
- Not redirect to another constructor:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A() = B;
|
|
}
|
|
class B implements A {
|
|
factory B() {
|
|
return B.named();
|
|
}
|
|
|
|
B.named();
|
|
}
|
|
```
|
|
|
|
- Not be a factory constructor:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A() = B;
|
|
}
|
|
class B implements A {
|
|
B();
|
|
B.named();
|
|
}
|
|
```
|
|
recursiveFactoryRedirect:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: recursiveConstructorRedirect
|
|
problemMessage: "Constructors can't redirect to themselves either directly or indirectly."
|
|
correctionMessage: Try changing one of the constructors in the loop to not redirect.
|
|
hasPublishedDocs: true
|
|
recursiveInterfaceInheritance:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class that implements itself recursively
|
|
String loop: a string representation of the implements loop
|
|
problemMessage: "'#className' can't be a superinterface of itself: #loop."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a circularity in the
|
|
type hierarchy. This happens when a type, either directly or indirectly,
|
|
is declared to be a subtype of itself.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `A` is
|
|
declared to be a subtype of `B`, and `B` is a subtype of `A`:
|
|
|
|
```dart
|
|
class [!A!] extends B {}
|
|
class B implements A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the type hierarchy so that there's no circularity.
|
|
recursiveInterfaceInheritanceExtends:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class that implements itself recursively
|
|
sharedName: recursiveInterfaceInheritance
|
|
problemMessage: "'#className' can't extend itself."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
7.10 Superinterfaces: It is a compile-time error if the interface of a
|
|
class <i>C</i> is a superinterface of itself.
|
|
|
|
8.1 Superinterfaces: It is a compile-time error if an interface is a
|
|
superinterface of itself.
|
|
|
|
7.9 Superclasses: It is a compile-time error if a class <i>C</i> is a
|
|
superclass of itself.
|
|
recursiveInterfaceInheritanceImplements:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class that implements itself recursively
|
|
sharedName: recursiveInterfaceInheritance
|
|
problemMessage: "'#className' can't implement itself."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
7.10 Superinterfaces: It is a compile-time error if the interface of a
|
|
class <i>C</i> is a superinterface of itself.
|
|
|
|
8.1 Superinterfaces: It is a compile-time error if an interface is a
|
|
superinterface of itself.
|
|
|
|
7.9 Superclasses: It is a compile-time error if a class <i>C</i> is a
|
|
superclass of itself.
|
|
recursiveInterfaceInheritanceOn:
|
|
type: compileTimeError
|
|
parameters:
|
|
String mixinName: the name of the mixin that constraints itself recursively
|
|
sharedName: recursiveInterfaceInheritance
|
|
problemMessage: "'#mixinName' can't use itself as a superclass constraint."
|
|
hasPublishedDocs: true
|
|
recursiveInterfaceInheritanceWith:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class that implements itself recursively
|
|
sharedName: recursiveInterfaceInheritance
|
|
problemMessage: "'#className' can't use itself as a mixin."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
7.10 Superinterfaces: It is a compile-time error if the interface of a
|
|
class <i>C</i> is a superinterface of itself.
|
|
|
|
8.1 Superinterfaces: It is a compile-time error if an interface is a
|
|
superinterface of itself.
|
|
|
|
7.9 Superclasses: It is a compile-time error if a class <i>C</i> is a
|
|
superclass of itself.
|
|
redirectGenerativeToMissingConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String constructorName: the name of the constructor
|
|
String className: the name of the class
|
|
problemMessage: "The constructor '#constructorName' couldn't be found in '#className'."
|
|
correctionMessage: "Try redirecting to a different constructor, or defining the constructor named '#constructorName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a generative constructor
|
|
redirects to a constructor that isn't defined.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor `C.a`
|
|
redirects to the constructor `C.b`, but `C.b` isn't defined:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : [!this.b()!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the missing constructor must be called, then define it:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : this.b();
|
|
C.b();
|
|
}
|
|
```
|
|
|
|
If the missing constructor doesn't need to be called, then remove the
|
|
redirect:
|
|
|
|
```dart
|
|
class C {
|
|
C.a();
|
|
}
|
|
```
|
|
redirectToAbstractClassConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String redirectingConstructorName: the name of the redirecting constructor
|
|
String abstractClass: the name of the abstract class defining the constructor being redirected to
|
|
problemMessage: "The redirecting constructor '#redirectingConstructorName' can't redirect to a constructor of the abstract class '#abstractClass'."
|
|
correctionMessage: Try redirecting to a constructor of a different class.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor redirects to a
|
|
constructor in an abstract class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the factory
|
|
constructor in `A` redirects to a constructor in `B`, but `B` is an
|
|
abstract class:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() = [!B!];
|
|
}
|
|
|
|
abstract class B implements A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the code redirects to the correct constructor, then change the class so
|
|
that it isn't abstract:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() = B;
|
|
}
|
|
|
|
class B implements A {}
|
|
```
|
|
|
|
Otherwise, change the factory constructor so that it either redirects to a
|
|
constructor in a concrete class, or has a concrete implementation.
|
|
redirectToInvalidFunctionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type redirectedType: the name of the redirected constructor
|
|
Type redirectingType: the name of the redirecting constructor
|
|
problemMessage: "The redirected constructor '#redirectedType' has incompatible parameters with '#redirectingType'."
|
|
correctionMessage: Try redirecting to a different constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a factory constructor attempts
|
|
to redirect to another constructor, but the two have incompatible
|
|
parameters. The parameters are compatible if all of the parameters of the
|
|
redirecting constructor can be passed to the other constructor and if the
|
|
other constructor doesn't require any parameters that aren't declared by
|
|
the redirecting constructor.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the constructor for `A`
|
|
doesn't declare a parameter that the constructor for `B` requires:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A() = [!B!];
|
|
}
|
|
|
|
class B implements A {
|
|
B(int x);
|
|
B.zero();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the constructor for `A`
|
|
declares a named parameter (`y`) that the constructor for `B` doesn't
|
|
allow:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A(int x, {int y}) = [!B!];
|
|
}
|
|
|
|
class B implements A {
|
|
B(int x);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a different constructor that is compatible with the redirecting
|
|
constructor, then redirect to that constructor:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A() = B.zero;
|
|
}
|
|
|
|
class B implements A {
|
|
B(int x);
|
|
B.zero();
|
|
}
|
|
```
|
|
|
|
Otherwise, update the redirecting constructor to be compatible:
|
|
|
|
```dart
|
|
abstract class A {
|
|
factory A(int x) = B;
|
|
}
|
|
|
|
class B implements A {
|
|
B(int x);
|
|
}
|
|
```
|
|
redirectToInvalidReturnType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type redirectedReturnType: the name of the redirected constructor's return type
|
|
Type redirectingReturnType: the name of the redirecting constructor's return type
|
|
problemMessage: "The return type '#redirectedReturnType' of the redirected constructor isn't a subtype of '#redirectingReturnType'."
|
|
correctionMessage: Try redirecting to a different constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a factory constructor redirects
|
|
to a constructor whose return type isn't a subtype of the type that the
|
|
factory constructor is declared to produce.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `A` isn't a subclass
|
|
of `C`, which means that the value returned by the constructor `A()`
|
|
couldn't be returned from the constructor `C()`:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B implements C {}
|
|
|
|
class C {
|
|
factory C() = [!A!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the factory constructor is redirecting to a constructor in the wrong
|
|
class, then update the factory constructor to redirect to the correct
|
|
constructor:
|
|
|
|
```dart
|
|
class A {}
|
|
|
|
class B implements C {}
|
|
|
|
class C {
|
|
factory C() = B;
|
|
}
|
|
```
|
|
|
|
If the class defining the constructor being redirected to is the class that
|
|
should be returned, then make it a subtype of the factory's return type:
|
|
|
|
```dart
|
|
class A implements C {}
|
|
|
|
class B implements C {}
|
|
|
|
class C {
|
|
factory C() = A;
|
|
}
|
|
```
|
|
redirectToMissingConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String constructorName: the name of the constructor
|
|
Type redirectedType: the type being redirected to
|
|
problemMessage: "The constructor '#constructorName' couldn't be found in '#redirectedType'."
|
|
correctionMessage: "Try redirecting to a different constructor, or define the constructor named '#constructorName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor redirects to a
|
|
constructor that doesn't exist.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the factory
|
|
constructor in `A` redirects to a constructor in `B` that doesn't exist:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() = [!B.name!];
|
|
}
|
|
|
|
class B implements A {
|
|
B();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the constructor being redirected to is correct, then define the
|
|
constructor:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() = B.name;
|
|
}
|
|
|
|
class B implements A {
|
|
B();
|
|
B.name();
|
|
}
|
|
```
|
|
|
|
If a different constructor should be invoked, then update the redirect:
|
|
|
|
```dart
|
|
class A {
|
|
factory A() = B;
|
|
}
|
|
|
|
class B implements A {
|
|
B();
|
|
}
|
|
```
|
|
redirectToNonClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the non-type referenced in the redirect
|
|
problemMessage: "The name '#name' isn't a type and can't be used in a redirected constructor."
|
|
correctionMessage: Try redirecting to a different constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
One way to implement a factory constructor is to redirect to another
|
|
constructor by referencing the name of the constructor. The analyzer
|
|
produces this diagnostic when the redirect is to something other than a
|
|
constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is a function:
|
|
|
|
```dart
|
|
C f() => throw 0;
|
|
|
|
class C {
|
|
factory C() = [!f!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the constructor isn't defined, then either define it or replace it with
|
|
a constructor that is defined.
|
|
|
|
If the constructor is defined but the class that defines it isn't visible,
|
|
then you probably need to add an import.
|
|
|
|
If you're trying to return the value returned by a function, then rewrite
|
|
the constructor to return the value from the constructor's body:
|
|
|
|
```dart
|
|
C f() => throw 0;
|
|
|
|
class C {
|
|
factory C() => f();
|
|
}
|
|
```
|
|
redirectToNonConstConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A constant redirecting constructor can't redirect to a non-constant constructor."
|
|
correctionMessage: Try redirecting to a different constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor marked as `const`
|
|
redirects to a constructor that isn't marked as `const`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor `C.a`
|
|
is marked as `const` but redirects to the constructor `C.b`, which isn't:
|
|
|
|
```dart
|
|
class C {
|
|
const C.a() : this.[!b!]();
|
|
C.b();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the non-constant constructor can be marked as `const`, then mark it as
|
|
`const`:
|
|
|
|
```dart
|
|
class C {
|
|
const C.a() : this.b();
|
|
const C.b();
|
|
}
|
|
```
|
|
|
|
If the non-constant constructor can't be marked as `const`, then either
|
|
remove the redirect or remove `const` from the redirecting constructor:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : this.b();
|
|
C.b();
|
|
}
|
|
```
|
|
redirectToTypeAliasExpandsToTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A redirecting constructor can't redirect to a type alias that expands to a type parameter."
|
|
correctionMessage: Try replacing it with a class.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a redirecting factory
|
|
constructor redirects to a type alias, and the type alias expands to one of
|
|
the type parameters of the type alias. This isn't allowed because the value
|
|
of the type parameter is a type rather than a class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the redirect to `B<A>`
|
|
is to a type alias whose value is `T`, even though it looks like the value
|
|
should be `A`:
|
|
|
|
```dart
|
|
class A implements C {}
|
|
|
|
typedef B<T> = T;
|
|
|
|
abstract class C {
|
|
factory C() = [!B!]<A>;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use either a class name or a type alias that is defined to be a class
|
|
rather than a type alias defined to be a type parameter:
|
|
|
|
```dart
|
|
class A implements C {}
|
|
|
|
abstract class C {
|
|
factory C() = A;
|
|
}
|
|
```
|
|
referencedBeforeDeclaration:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the variable
|
|
problemMessage: "Local variable '#name' can't be referenced before it is declared."
|
|
correctionMessage: "Try moving the declaration to before the first use, or renaming the local variable so that it doesn't hide a name from an enclosing scope."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a variable is referenced before
|
|
it's declared. In Dart, variables are visible everywhere in the block in
|
|
which they are declared, but can only be referenced after they are
|
|
declared.
|
|
|
|
The analyzer also produces a context message that indicates where the
|
|
declaration is located.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `i` is used before it
|
|
is declared:
|
|
|
|
```dart
|
|
%language=2.9
|
|
%ignore=not_assigned_potentially_non_nullable_local_variable
|
|
void f() {
|
|
print([!i!]);
|
|
int i = 5;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended to reference the local variable, move the declaration
|
|
before the first reference:
|
|
|
|
```dart
|
|
%language=2.9
|
|
void f() {
|
|
int i = 5;
|
|
print(i);
|
|
}
|
|
```
|
|
|
|
If you intended to reference a name from an outer scope, such as a
|
|
parameter, instance field or top-level variable, then rename the local
|
|
declaration so that it doesn't hide the outer variable.
|
|
|
|
```dart
|
|
%language=2.9
|
|
void f(int i) {
|
|
print(i);
|
|
int x = 5;
|
|
print(x);
|
|
}
|
|
```
|
|
refutablePatternInIrrefutableContext:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Refutable patterns can't be used in an irrefutable context.
|
|
correctionMessage: Try using an if-case, a 'switch' statement, or a 'switch' expression instead.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a [refutable pattern][] is used
|
|
in a context where only an [irrefutable pattern][] is allowed.
|
|
|
|
The refutable patterns that are disallowed are:
|
|
- logical-or
|
|
- relational
|
|
- null-check
|
|
- constant
|
|
|
|
The contexts that are checked are:
|
|
- pattern-based variable declarations
|
|
- pattern-based for loops
|
|
- assignments with a pattern on the left-hand side
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the null-check
|
|
pattern, which is a refutable pattern, is in a pattern-based variable
|
|
declaration, which doesn't allow refutable patterns:
|
|
|
|
```dart
|
|
void f(int? x) {
|
|
var ([!_?!]) = x;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rewrite the code to not use a refutable pattern in an irrefutable context.
|
|
relationalPatternOperandTypeNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type operandType: the operand type
|
|
Type parameterType: the parameter type of the invoked operator
|
|
String operator: the name of the invoked operator
|
|
problemMessage: "The constant expression type '#operandType' is not assignable to the parameter type '#parameterType' of the '#operator' operator."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the operand of a relational
|
|
pattern has a type that isn't assignable to the parameter of the operator
|
|
that will be invoked.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the operand in the
|
|
relational pattern (`0`) is an `int`, but the `>` operator defined in `C`
|
|
expects an object of type `C`:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
|
|
bool operator >(C other) => true;
|
|
}
|
|
|
|
void f(C c) {
|
|
switch (c) {
|
|
case > [!0!]:
|
|
print('positive');
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the switch is using the correct value, then change the case to compare
|
|
the value to the right type of object:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
|
|
bool operator >(C other) => true;
|
|
}
|
|
|
|
void f(C c) {
|
|
switch (c) {
|
|
case > const C():
|
|
print('positive');
|
|
}
|
|
}
|
|
```
|
|
|
|
If the switch is using the wrong value, then change the expression used to
|
|
compute the value being matched:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
|
|
bool operator >(C other) => true;
|
|
|
|
int get toInt => 0;
|
|
}
|
|
|
|
void f(C c) {
|
|
switch (c.toInt) {
|
|
case > 0:
|
|
print('positive');
|
|
}
|
|
}
|
|
```
|
|
|
|
relationalPatternOperatorReturnTypeNotAssignableToBool:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The return type of operators used in relational patterns must be assignable to 'bool'.
|
|
correctionMessage: Try updating the operator declaration to return 'bool'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a relational pattern references
|
|
an operator that doesn't produce a value of type `bool`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the operator `>`, used
|
|
in the relational pattern `> c2`, returns a value of type `int` rather
|
|
than a `bool`:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
|
|
int operator >(C c) => 3;
|
|
|
|
bool operator <(C c) => false;
|
|
}
|
|
|
|
const C c2 = C();
|
|
|
|
void f(C c1) {
|
|
if (c1 case [!>!] c2) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a different operator that should be used, then change the
|
|
operator:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
|
|
int operator >(C c) => 3;
|
|
|
|
bool operator <(C c) => false;
|
|
}
|
|
|
|
const C c2 = C();
|
|
|
|
void f(C c1) {
|
|
if (c1 case < c2) {}
|
|
}
|
|
```
|
|
|
|
If the operator is expected to return `bool`, then update the declaration
|
|
of the operator:
|
|
|
|
```dart
|
|
class C {
|
|
const C();
|
|
|
|
bool operator >(C c) => true;
|
|
|
|
bool operator <(C c) => false;
|
|
}
|
|
|
|
const C c2 = C();
|
|
|
|
void f(C c1) {
|
|
if (c1 case > c2) {}
|
|
}
|
|
```
|
|
restElementInMapPattern:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A map pattern can't contain a rest pattern.
|
|
correctionMessage: Try removing the rest pattern.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a map pattern contains a rest
|
|
pattern. Map patterns match a map with more keys
|
|
than those explicitly given in the pattern (as long as the given keys match),
|
|
so a rest pattern is unnecessary.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the map pattern contains
|
|
a rest pattern:
|
|
|
|
```dart
|
|
void f(Map<int, String> x) {
|
|
if (x case {0: _, [!...!]}) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the rest pattern:
|
|
|
|
```dart
|
|
void f(Map<int, String> x) {
|
|
if (x case {0: _}) {}
|
|
}
|
|
```
|
|
rethrowOutsideCatch:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A rethrow must be inside of a catch clause.
|
|
correctionMessage: "Try moving the expression into a catch clause, or using a 'throw' expression."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `rethrow` statement is outside
|
|
a `catch` clause. The `rethrow` statement is used to throw a caught
|
|
exception again, but there's no caught exception outside of a `catch`
|
|
clause.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the`rethrow` statement
|
|
is outside of a `catch` clause:
|
|
|
|
```dart
|
|
void f() {
|
|
[!rethrow!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're trying to rethrow an exception, then wrap the `rethrow` statement
|
|
in a `catch` clause:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} catch (exception) {
|
|
rethrow;
|
|
}
|
|
}
|
|
```
|
|
|
|
If you're trying to throw a new exception, then replace the `rethrow`
|
|
statement with a `throw` expression:
|
|
|
|
```dart
|
|
void f() {
|
|
throw UnsupportedError('Not yet implemented');
|
|
}
|
|
```
|
|
returnInGenerativeConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constructors can't return values."
|
|
correctionMessage: Try removing the return statement or using a factory constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a generative constructor
|
|
contains a `return` statement that specifies a value to be returned.
|
|
Generative constructors always return the object that was created, and
|
|
therefore can't return a different object.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `return` statement
|
|
has an expression:
|
|
|
|
```dart
|
|
class C {
|
|
C() {
|
|
return [!this!];
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the constructor should create a new instance, then remove either the
|
|
`return` statement or the expression:
|
|
|
|
```dart
|
|
class C {
|
|
C();
|
|
}
|
|
```
|
|
|
|
If the constructor shouldn't create a new instance, then convert it to be a
|
|
factory constructor:
|
|
|
|
```dart
|
|
class C {
|
|
factory C() {
|
|
return _instance;
|
|
}
|
|
|
|
static C _instance = C._();
|
|
|
|
C._();
|
|
}
|
|
```
|
|
returnInGenerator:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Can't return a value from a generator function that uses the 'async*' or 'sync*' modifier."
|
|
correctionMessage: "Try replacing 'return' with 'yield', using a block function body, or changing the method body modifier."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a generator function (one whose
|
|
body is marked with either `async*` or `sync*`) uses either a `return`
|
|
statement to return a value or implicitly returns a value because of using
|
|
`=>`. In any of these cases, they should use `yield` instead of `return`.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the method `f` is a
|
|
generator and is using `return` to return a value:
|
|
|
|
```dart
|
|
Iterable<int> f() sync* {
|
|
[!return!] 3;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the function `f` is a
|
|
generator and is implicitly returning a value:
|
|
|
|
```dart
|
|
Stream<int> f() async* [!=>!] 3;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function is using `=>` for the body of the function, then convert it
|
|
to a block function body, and use `yield` to return a value:
|
|
|
|
```dart
|
|
Stream<int> f() async* {
|
|
yield 3;
|
|
}
|
|
```
|
|
|
|
If the method is intended to be a generator, then use `yield` to return a
|
|
value:
|
|
|
|
```dart
|
|
Iterable<int> f() sync* {
|
|
yield 3;
|
|
}
|
|
```
|
|
|
|
If the method isn't intended to be a generator, then remove the modifier
|
|
from the body (or use `async` if you're returning a future):
|
|
|
|
```dart
|
|
int f() {
|
|
return 3;
|
|
}
|
|
```
|
|
returnOfInvalidTypeFromConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualReturnType: the return type as declared in the return statement
|
|
Type expectedReturnType: the expected return type as defined by the enclosing class
|
|
String constructorName: the name of the constructor
|
|
sharedName: returnOfInvalidType
|
|
problemMessage: "A value of type '#actualReturnType' can't be returned from the constructor '#constructorName' because it has a return type of '#expectedReturnType'."
|
|
hasPublishedDocs: true
|
|
returnOfInvalidTypeFromFunction:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualReturnType: the return type as declared in the return statement
|
|
Type expectedReturnType: the expected return type as defined by the method
|
|
String methodName: the name of the method
|
|
sharedName: returnOfInvalidType
|
|
problemMessage: "A value of type '#actualReturnType' can't be returned from the function '#methodName' because it has a return type of '#expectedReturnType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function returns a
|
|
value whose type isn't assignable to the declared return type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` has a return type
|
|
of `String` but is returning an `int`:
|
|
|
|
```dart
|
|
String f() => [!3!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the return type is correct, then replace the value being returned with a
|
|
value of the correct type, possibly by converting the existing value:
|
|
|
|
```dart
|
|
String f() => 3.toString();
|
|
```
|
|
|
|
If the value is correct, then change the return type to match:
|
|
|
|
```dart
|
|
int f() => 3;
|
|
```
|
|
returnOfInvalidTypeFromMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualReturnType: the type of the expression in the return statement
|
|
Type expectedReturnType: the expected return type as defined by the method
|
|
String methodName: the name of the method
|
|
sharedName: returnOfInvalidType
|
|
problemMessage: "A value of type '#actualReturnType' can't be returned from the method '#methodName' because it has a return type of '#expectedReturnType'."
|
|
hasPublishedDocs: true
|
|
returnOfInvalidTypeFromClosure:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualReturnType: the return type as declared in the return statement
|
|
Type expectedReturnType: the expected return type as defined by the method
|
|
problemMessage: The returned type '#actualReturnType' isn't returnable from a '#expectedReturnType' function, as required by the closure's context.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the static type of a returned
|
|
expression isn't assignable to the return type that the closure is required
|
|
to have.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` is defined to be a
|
|
function that returns a `String`, but the closure assigned to it returns an
|
|
`int`:
|
|
|
|
```dart
|
|
String Function(String) f = (s) => [!3!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the return type is correct, then replace the returned value with a value
|
|
of the correct type, possibly by converting the existing value:
|
|
|
|
```dart
|
|
String Function(String) f = (s) => 3.toString();
|
|
```
|
|
returnWithoutValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The return value is missing after 'return'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds a `return` statement
|
|
without an expression in a function that declares a return type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `f` is
|
|
expected to return an `int`, but no value is being returned:
|
|
|
|
```dart
|
|
int f() {
|
|
[!return!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an expression that computes the value to be returned:
|
|
|
|
```dart
|
|
int f() {
|
|
return 0;
|
|
}
|
|
```
|
|
sealedClassSubtypeOutsideOfLibrary:
|
|
type: compileTimeError
|
|
parameters:
|
|
String sealedClassName: the name of the sealed class being extended, implemented, or mixed in
|
|
sharedName: invalidUseOfTypeOutsideLibrary
|
|
problemMessage: "The class '#sealedClassName' can't be extended, implemented, or mixed in outside of its library because it's a sealed class."
|
|
hasPublishedDocs: true
|
|
setElementTypeNotAssignableNullability:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the actual type of the set element
|
|
Type expectedType: the expected type of the set element
|
|
sharedName: setElementTypeNotAssignable
|
|
problemMessage: "The element type '#actualType' can't be assigned to the set type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
setElementTypeNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the actual type of the set element
|
|
Type expectedType: the expected type of the set element
|
|
problemMessage: "The element type '#actualType' can't be assigned to the set type '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an element in a set literal has
|
|
a type that isn't assignable to the element type of the set.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of the string
|
|
literal `'0'` is `String`, which isn't assignable to `int`, the element
|
|
type of the set:
|
|
|
|
```dart
|
|
var s = <int>{[!'0'!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the element type of the set literal is wrong, then change the element
|
|
type of the set:
|
|
|
|
```dart
|
|
var s = <String>{'0'};
|
|
```
|
|
|
|
If the type of the element is wrong, then change the element:
|
|
|
|
```dart
|
|
var s = <int>{'0'.length};
|
|
```
|
|
sharedDeferredPrefix:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The prefix of a deferred import can't be used in other import directives."
|
|
correctionMessage: Try renaming one of the prefixes.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a prefix in a deferred import is
|
|
also used as a prefix in other imports (whether deferred or not). The
|
|
prefix in a deferred import can't be shared with other imports because the
|
|
prefix is used to load the imported library.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the prefix `x` is used
|
|
as the prefix for a deferred import and is also used for one other import:
|
|
|
|
```dart
|
|
import 'dart:math' [!deferred!] as x;
|
|
import 'dart:convert' as x;
|
|
|
|
var y = x.json.encode(x.min(0, 1));
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can use a different name for the deferred import, then do so:
|
|
|
|
```dart
|
|
import 'dart:math' deferred as math;
|
|
import 'dart:convert' as x;
|
|
|
|
var y = x.json.encode(math.min(0, 1));
|
|
```
|
|
|
|
If you can use a different name for the other imports, then do so:
|
|
|
|
```dart
|
|
import 'dart:math' deferred as x;
|
|
import 'dart:convert' as convert;
|
|
|
|
var y = convert.json.encode(x.min(0, 1));
|
|
```
|
|
spreadExpressionFromDeferredLibrary:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Constant values from a deferred library can't be spread into a const literal."
|
|
correctionMessage: Try making the deferred import non-deferred.
|
|
hasPublishedDocs: false
|
|
staticAccessToInstanceMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the instance member
|
|
problemMessage: "Instance member '#name' can't be accessed using static access."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class name is used to access
|
|
an instance field. Instance fields don't exist on a class; they exist only
|
|
on an instance of the class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` is an instance
|
|
field:
|
|
|
|
```dart
|
|
class C {
|
|
static int a = 0;
|
|
|
|
int b = 0;
|
|
}
|
|
|
|
int f() => C.[!b!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intend to access a static field, then change the name of the field
|
|
to an existing static field:
|
|
|
|
```dart
|
|
class C {
|
|
static int a = 0;
|
|
|
|
int b = 0;
|
|
}
|
|
|
|
int f() => C.a;
|
|
```
|
|
|
|
If you intend to access the instance field, then use an instance of the
|
|
class to access the field:
|
|
|
|
```dart
|
|
class C {
|
|
static int a = 0;
|
|
|
|
int b = 0;
|
|
}
|
|
|
|
int f(C c) => c.b;
|
|
```
|
|
subtypeOfBaseIsNotBaseFinalOrSealed:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subtypeName: the name of the subtype that is not 'base', 'final', or 'sealed'
|
|
String supertypeName: the name of the 'base' supertype
|
|
sharedName: subtypeOfBaseOrFinalIsNotBaseFinalOrSealed
|
|
problemMessage: "The type '#subtypeName' must be 'base', 'final' or 'sealed' because the supertype '#supertypeName' is 'base'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class or mixin has a direct
|
|
or indirect supertype that is either `base` or `final`, but the class or
|
|
mixin itself isn't marked either `base`, `final`, or `sealed`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B` is a
|
|
subtype of `A`, and `A` is a `base` class, but `B` is neither `base`,
|
|
`final` or `sealed`:
|
|
|
|
```dart
|
|
base class A {}
|
|
class [!B!] extends A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add either `base`, `final` or `sealed` to the class or mixin declaration:
|
|
|
|
```dart
|
|
base class A {}
|
|
final class B extends A {}
|
|
```
|
|
subtypeOfFinalIsNotBaseFinalOrSealed:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subtypeName: the name of the subtype that is not 'base', 'final', or 'sealed'
|
|
String supertypeName: the name of the 'final' supertype
|
|
sharedName: subtypeOfBaseOrFinalIsNotBaseFinalOrSealed
|
|
problemMessage: "The type '#subtypeName' must be 'base', 'final' or 'sealed' because the supertype '#supertypeName' is 'final'."
|
|
hasPublishedDocs: true
|
|
superFormalParameterTypeIsNotSubtypeOfAssociated:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type parameterType: the type of super-parameter
|
|
Type superParameterType: the type of associated super-constructor parameter
|
|
problemMessage: The type '#parameterType' of this parameter isn't a subtype of the type '#superParameterType' of the associated super constructor parameter.
|
|
correctionMessage: Try removing the explicit type annotation from the parameter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of a super parameter
|
|
isn't a subtype of the corresponding parameter from the super constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of the super
|
|
parameter `x` in the constructor for `B` isn't a subtype of the parameter
|
|
`x` in the constructor for `A`:
|
|
|
|
```dart
|
|
class A {
|
|
A(num x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(String super.[!x!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the super parameter can be the same as the parameter from
|
|
the super constructor, then remove the type annotation from the super
|
|
parameter (if the type is implicit, it is inferred from the type in the
|
|
super constructor):
|
|
|
|
```dart
|
|
class A {
|
|
A(num x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.x);
|
|
}
|
|
```
|
|
|
|
If the type of the super parameter can be a subtype of the corresponding
|
|
parameter's type, then change the type of the super parameter:
|
|
|
|
```dart
|
|
class A {
|
|
A(num x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(int super.x);
|
|
}
|
|
```
|
|
|
|
If the type of the super parameter can't be changed, then use a normal
|
|
parameter instead of a super parameter:
|
|
|
|
```dart
|
|
class A {
|
|
A(num x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(String x) : super(x.length);
|
|
}
|
|
```
|
|
superFormalParameterWithoutAssociatedNamed:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: No associated named super constructor parameter.
|
|
correctionMessage: Try changing the name to the name of an existing named super constructor parameter, or creating such named parameter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a named super parameter
|
|
in a constructor and the implicitly or explicitly invoked super
|
|
constructor doesn't have a named parameter with the same name.
|
|
|
|
Named super parameters are associated by name with named parameters in the
|
|
super constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor in `A`
|
|
doesn't have a parameter named `y`:
|
|
|
|
```dart
|
|
class A {
|
|
A({int? x});
|
|
}
|
|
|
|
class B extends A {
|
|
B({super.[!y!]});
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the super parameter should be associated with an existing parameter
|
|
from the super constructor, then change the name to match the name of the
|
|
corresponding parameter:
|
|
|
|
```dart
|
|
class A {
|
|
A({int? x});
|
|
}
|
|
|
|
class B extends A {
|
|
B({super.x});
|
|
}
|
|
```
|
|
|
|
If the super parameter should be associated with a parameter that hasn't
|
|
yet been added to the super constructor, then add it:
|
|
|
|
```dart
|
|
class A {
|
|
A({int? x, int? y});
|
|
}
|
|
|
|
class B extends A {
|
|
B({super.y});
|
|
}
|
|
```
|
|
|
|
If the super parameter doesn't correspond to a named parameter from the
|
|
super constructor, then change it to be a normal parameter:
|
|
|
|
```dart
|
|
class A {
|
|
A({int? x});
|
|
}
|
|
|
|
class B extends A {
|
|
B({int? y});
|
|
}
|
|
```
|
|
superFormalParameterWithoutAssociatedPositional:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: No associated positional super constructor parameter.
|
|
correctionMessage: Try using a normal parameter, or adding more positional parameters to the super constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a positional super
|
|
parameter in a constructor and the implicitly or explicitly invoked super
|
|
constructor doesn't have a positional parameter at the corresponding
|
|
index.
|
|
|
|
Positional super parameters are associated with positional parameters in
|
|
the super constructor by their index. That is, the first super parameter
|
|
is associated with the first positional parameter in the super
|
|
constructor, the second with the second, and so on.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the constructor in `B`
|
|
has a positional super parameter, but there's no positional parameter in
|
|
the super constructor in `A`:
|
|
|
|
```dart
|
|
class A {
|
|
A({int? x});
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.[!x!]);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the constructor in `B`
|
|
has two positional super parameters, but there's only one positional
|
|
parameter in the super constructor in `A`, which means that there's no
|
|
corresponding parameter for `y`:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.x, super.[!y!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the super constructor should have a positional parameter corresponding
|
|
to the super parameter, then update the super constructor appropriately:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x, int y);
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.x, super.y);
|
|
}
|
|
```
|
|
|
|
If the super constructor is correct, or can't be changed, then convert the
|
|
super parameter into a normal parameter:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.x, int y);
|
|
}
|
|
```
|
|
implementsDeferredClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: subtypeOfDeferredClass
|
|
problemMessage: "Classes and mixins can't implement deferred classes."
|
|
correctionMessage: Try specifying a different interface, removing the class from the list, or changing the import to not be deferred.
|
|
hasPublishedDocs: true
|
|
mixinDeferredClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: subtypeOfDeferredClass
|
|
problemMessage: "Classes can't mixin deferred classes."
|
|
correctionMessage: Try changing the import to not be deferred.
|
|
hasPublishedDocs: true
|
|
extendsDeferredClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: subtypeOfDeferredClass
|
|
problemMessage: "Classes can't extend deferred classes."
|
|
correctionMessage: Try specifying a different superclass, or removing the extends clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type (class or mixin) is a
|
|
subtype of a class from a library being imported using a deferred import.
|
|
The supertypes of a type must be compiled at the same time as the type, and
|
|
classes from deferred libraries aren't compiled until the library is
|
|
loaded.
|
|
|
|
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 class `A`:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
class A {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the superclass of `B`
|
|
is declared in a deferred library:
|
|
|
|
```dart
|
|
import 'a.dart' deferred as a;
|
|
|
|
class B extends [!a.A!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to create a subtype of a type from the deferred library, then
|
|
remove the `deferred` keyword:
|
|
|
|
```dart
|
|
import 'a.dart' as a;
|
|
|
|
class B extends a.A {}
|
|
```
|
|
extendsDisallowedClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type disallowedType: the name of the disallowed type
|
|
sharedName: subtypeOfDisallowedType
|
|
problemMessage: "Classes can't extend '#disallowedType'."
|
|
correctionMessage: Try specifying a different superclass, or removing the extends clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when one of the restricted classes is
|
|
used in either an `extends`, `implements`, `with`, or `on` clause. The
|
|
classes `bool`, `double`, `FutureOr`, `int`, `Null`, `num`, and `String`
|
|
are all restricted in this way, to allow for more efficient
|
|
implementations.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `String` is used in an
|
|
`extends` clause:
|
|
|
|
```dart
|
|
class A extends [!String!] {}
|
|
```
|
|
|
|
The following code produces this diagnostic because `String` is used in an
|
|
`implements` clause:
|
|
|
|
```dart
|
|
class B implements [!String!] {}
|
|
```
|
|
|
|
The following code produces this diagnostic because `String` is used in a
|
|
`with` clause:
|
|
|
|
```dart
|
|
class C with [!String!] {}
|
|
```
|
|
|
|
The following code produces this diagnostic because `String` is used in an
|
|
`on` clause:
|
|
|
|
```dart
|
|
mixin M on [!String!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a different type should be specified, then replace the type:
|
|
|
|
```dart
|
|
class A extends Object {}
|
|
```
|
|
|
|
If there isn't a different type that would be appropriate, then remove the
|
|
type, and possibly the whole clause:
|
|
|
|
```dart
|
|
class B {}
|
|
```
|
|
mixinOfDisallowedClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type disallowedType: the name of the disallowed type
|
|
sharedName: subtypeOfDisallowedType
|
|
problemMessage: "Classes can't mixin '#disallowedType'."
|
|
correctionMessage: Try specifying a different class or mixin, or remove the class or mixin from the list.
|
|
hasPublishedDocs: true
|
|
mixinSuperClassConstraintDisallowedClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type disallowedType: the name of the disallowed type
|
|
sharedName: subtypeOfDisallowedType
|
|
problemMessage: "'#disallowedType' can't be used as a superclass constraint."
|
|
correctionMessage: "Try specifying a different super-class constraint, or remove the 'on' clause."
|
|
hasPublishedDocs: true
|
|
implementsDisallowedClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type disallowedType: the name of the disallowed type
|
|
sharedName: subtypeOfDisallowedType
|
|
problemMessage: "Classes and mixins can't implement '#disallowedType'."
|
|
correctionMessage: Try specifying a different interface, or remove the class from the list.
|
|
hasPublishedDocs: true
|
|
extendsTypeAliasExpandsToTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: supertypeExpandsToTypeParameter
|
|
problemMessage: "A type alias that expands to a type parameter can't be used as a superclass."
|
|
correctionMessage: Try specifying a different superclass, or removing the extends clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type alias that expands to a
|
|
type parameter is used in an `extends`, `implements`, `with`, or `on`
|
|
clause.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type alias `T`,
|
|
which expands to the type parameter `S`, is used in the `extends` clause of
|
|
the class `C`:
|
|
|
|
```dart
|
|
typedef T<S> = S;
|
|
|
|
class C extends [!T!]<Object> {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use the value of the type argument directly:
|
|
|
|
```dart
|
|
typedef T<S> = S;
|
|
|
|
class C extends Object {}
|
|
```
|
|
mixinOnTypeAliasExpandsToTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: supertypeExpandsToTypeParameter
|
|
problemMessage: "A type alias that expands to a type parameter can't be used as a superclass constraint."
|
|
hasPublishedDocs: true
|
|
mixinOfTypeAliasExpandsToTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: supertypeExpandsToTypeParameter
|
|
problemMessage: "A type alias that expands to a type parameter can't be mixed in."
|
|
hasPublishedDocs: true
|
|
implementsTypeAliasExpandsToTypeParameter:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: supertypeExpandsToTypeParameter
|
|
problemMessage: "A type alias that expands to a type parameter can't be implemented."
|
|
correctionMessage: Try specifying a class or mixin, or removing the list.
|
|
hasPublishedDocs: true
|
|
superInitializerInObject:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The class 'Object' can't invoke a constructor from a superclass."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
7.6.1 Generative Constructors: Let <i>k</i> be a generative constructor. It
|
|
is a compile-time error if a generative constructor of class Object
|
|
includes a superinitializer.
|
|
superInvocationNotLast:
|
|
type: compileTimeError
|
|
parameters: none
|
|
previousName: INVALID_SUPER_INVOCATION
|
|
problemMessage: "The superconstructor call must be last in an initializer list."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the initializer list of a
|
|
constructor contains an invocation of a constructor in the superclass, but
|
|
the invocation isn't the last item in the initializer list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the invocation of the
|
|
superclass' constructor isn't the last item in the initializer list:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(int x) : [!super!](x), assert(x >= 0);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Move the invocation of the superclass' constructor to the end of the
|
|
initializer list:
|
|
|
|
```dart
|
|
class A {
|
|
A(int x);
|
|
}
|
|
|
|
class B extends A {
|
|
B(int x) : assert(x >= 0), super(x);
|
|
}
|
|
```
|
|
superInEnumConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The enum constructor can't have a 'super' initializer.
|
|
correctionMessage: Try removing the 'super' invocation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the initializer list in a
|
|
constructor in an enum contains an invocation of a super constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor in
|
|
the enum `E` has a super constructor invocation in the initializer list:
|
|
|
|
```dart
|
|
enum E {
|
|
e;
|
|
|
|
const E() : [!super!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the super constructor invocation:
|
|
|
|
```dart
|
|
enum E {
|
|
e;
|
|
|
|
const E();
|
|
}
|
|
```
|
|
superInExtension:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The 'super' keyword can't be used in an extension because an extension doesn't have a superclass."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member declared inside an
|
|
extension uses the `super` keyword . Extensions aren't classes and don't
|
|
have superclasses, so the `super` keyword serves no purpose.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `super` can't be used
|
|
in an extension:
|
|
|
|
```dart
|
|
extension E on Object {
|
|
String get displayString => [!super!].toString();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the `super` keyword :
|
|
|
|
```dart
|
|
extension E on Object {
|
|
String get displayString => toString();
|
|
}
|
|
```
|
|
superInExtensionType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The 'super' keyword can't be used in an extension type because an extension type doesn't have a superclass."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when `super` is used in an instance
|
|
member of an extension type. Extension types don't have superclasses, so
|
|
there's no inherited member that could be invoked.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because :
|
|
|
|
```dart
|
|
extension type E(String s) {
|
|
void m() {
|
|
[!super!].m();
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace or remove the `super` invocation:
|
|
|
|
```dart
|
|
extension type E(String s) {
|
|
void m() {
|
|
s.toLowerCase();
|
|
}
|
|
}
|
|
```
|
|
superInInvalidContext:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Invalid context for 'super' invocation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the keyword `super` is used
|
|
outside of an instance method.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `super` is used in a
|
|
top-level function:
|
|
|
|
```dart
|
|
void f() {
|
|
[!super!].f();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rewrite the code to not use `super`.
|
|
superInRedirectingConstructor:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The redirecting constructor can't have a 'super' initializer."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor that redirects to
|
|
another constructor also attempts to invoke a constructor from the
|
|
superclass. The superclass constructor will be invoked when the constructor
|
|
that the redirecting constructor is redirected to is invoked.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor `C.a`
|
|
both redirects to `C.b` and invokes a constructor from the superclass:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : this.b(), [!super()!];
|
|
C.b();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the invocation of the `super` constructor:
|
|
|
|
```dart
|
|
class C {
|
|
C.a() : this.b();
|
|
C.b();
|
|
}
|
|
```
|
|
switchCaseCompletesNormally:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The 'case' shouldn't complete normally."
|
|
correctionMessage: "Try adding 'break', 'return', or 'throw'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the statements following a
|
|
`case` label in a `switch` statement could fall through to the next `case`
|
|
or `default` label.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `case` label with
|
|
a value of zero (`0`) falls through to the `default` statements:
|
|
|
|
```dart
|
|
%language=2.18
|
|
void f(int a) {
|
|
switch (a) {
|
|
[!case!] 0:
|
|
print(0);
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the flow of control so that the `case` won't fall through. There
|
|
are several ways that this can be done, including adding one of the
|
|
following at the end of the current list of statements:
|
|
- a `return` statement,
|
|
- a `throw` expression,
|
|
- a `break` statement,
|
|
- a `continue`, or
|
|
- an invocation of a function or method whose return type is `Never`.
|
|
switchExpressionNotAssignable:
|
|
type: compileTimeError
|
|
parameters:
|
|
String p0: the static type of the switch expression
|
|
String p1: the static type of the case expressions
|
|
removedIn: "3.0"
|
|
problemMessage: "Type '#p0' of the switch expression isn't assignable to the type '#p1' of case expressions."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of the expression in a
|
|
`switch` statement isn't assignable to the type of the expressions in the
|
|
`case` clauses.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of `s`
|
|
(`String`) isn't assignable to the type of `0` (`int`):
|
|
|
|
```dart
|
|
%language=2.9
|
|
void f(String s) {
|
|
switch ([!s!]) {
|
|
case 0:
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the `case` expressions is correct, then change the
|
|
expression in the `switch` statement to have the correct type:
|
|
|
|
```dart
|
|
%language=2.9
|
|
void f(String s) {
|
|
switch (int.parse(s)) {
|
|
case 0:
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the type of the `switch` expression is correct, then change the `case`
|
|
expressions to have the correct type:
|
|
|
|
```dart
|
|
%language=2.9
|
|
void f(String s) {
|
|
switch (s) {
|
|
case '0':
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
tearoffOfGenerativeConstructorOfAbstractClass:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "A generative constructor of an abstract class can't be torn off."
|
|
correctionMessage: Try tearing off a constructor of a concrete class, or a non-generative constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a generative constructor from an
|
|
abstract class is being torn off. This isn't allowed because it isn't valid
|
|
to create an instance of an abstract class, which means that there isn't
|
|
any valid use for the torn off constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constructor `C.new`
|
|
is being torn off and the class `C` is an abstract class:
|
|
|
|
```dart
|
|
abstract class C {
|
|
C();
|
|
}
|
|
|
|
void f() {
|
|
[!C.new!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Tear off the constructor of a concrete class.
|
|
throwOfInvalidType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type that can't be thrown
|
|
problemMessage: "The type '#type' of the thrown expression must be assignable to 'Object'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of the expression in a
|
|
throw expression isn't assignable to `Object`. It isn't valid to throw
|
|
`null`, so it isn't valid to use an expression that might evaluate to
|
|
`null`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `s` might be `null`:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
throw [!s!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an explicit null-check to the expression:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
throw s!;
|
|
}
|
|
```
|
|
topLevelCycle:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the element whose type could not be inferred.
|
|
String cycle: The names of the elements in the cycle (sorted and comma-separated).
|
|
problemMessage: "The type of '#name' can't be inferred because it depends on itself through the cycle: #cycle."
|
|
correctionMessage: Try adding an explicit type to one or more of the variables in the cycle in order to break the cycle.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a top-level variable has no type
|
|
annotation and the variable's initializer refers to the variable, either
|
|
directly or indirectly.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the variables `x` and
|
|
`y` are defined in terms of each other, and neither has an explicit type,
|
|
so the type of the other can't be inferred:
|
|
|
|
```dart
|
|
var x = y;
|
|
var y = [!x!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the two variables don't need to refer to each other, then break the
|
|
cycle:
|
|
|
|
```dart
|
|
var x = 0;
|
|
var y = x;
|
|
```
|
|
|
|
If the two variables need to refer to each other, then give at least one of
|
|
them an explicit type:
|
|
|
|
```dart
|
|
int x = y;
|
|
var y = x;
|
|
```
|
|
|
|
Note, however, that while this code doesn't produce any diagnostics, it
|
|
will produce a stack overflow at runtime unless at least one of the
|
|
variables is assigned a value that doesn't depend on the other variables
|
|
before any of the variables in the cycle are referenced.
|
|
typeAliasCannotReferenceItself:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Typedefs can't reference themselves directly or recursively via another typedef."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a typedef refers to itself,
|
|
either directly or indirectly.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `F` depends on itself
|
|
indirectly through `G`:
|
|
|
|
```dart
|
|
typedef [!F!] = void Function(G);
|
|
typedef G = void Function(F);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change one or more of the typedefs in the cycle so that none of them refer
|
|
to themselves:
|
|
|
|
```dart
|
|
typedef F = void Function(G);
|
|
typedef G = void Function(int);
|
|
```
|
|
typeAnnotationDeferredClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeName: the name of the type that is deferred and being used in a type annotation
|
|
problemMessage: "The deferred type '#typeName' can't be used in a declaration, cast, or type test."
|
|
correctionMessage: Try using a different type, or changing the import to not be deferred.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type annotation is in a
|
|
variable declaration, or the type used in a cast (`as`) or type test (`is`)
|
|
is a type declared in a library that is imported using a deferred import.
|
|
These types are required to be available at compile time, but aren't.
|
|
|
|
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 type of the
|
|
parameter `f` is imported from a deferred library:
|
|
|
|
```dart
|
|
import 'dart:io' deferred as io;
|
|
|
|
void f([!io.File!] f) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to reference the imported type, then remove the `deferred`
|
|
keyword:
|
|
|
|
```dart
|
|
import 'dart:io' as io;
|
|
|
|
void f(io.File f) {}
|
|
```
|
|
|
|
If the import is required to be deferred and there's another type that is
|
|
appropriate, then use that type in place of the type from the deferred
|
|
library.
|
|
typeArgumentNotMatchingBounds:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type nonConformingType: the name of the type used in the instance creation that should be limited by the bound as specified in the class declaration
|
|
String typeParameterName: the name of the type parameter
|
|
Type bound: the substituted bound of the type parameter
|
|
problemMessage: "'#nonConformingType' doesn't conform to the bound '#bound' of the type parameter '#typeParameterName'."
|
|
correctionMessage: "Try using a type that is or is a subclass of '#bound'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type argument isn't the same
|
|
as or a subclass of the bounds of the corresponding type parameter.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `String` isn't a
|
|
subclass of `num`:
|
|
|
|
```dart
|
|
class A<E extends num> {}
|
|
|
|
var a = A<[!String!]>();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the type argument to be a subclass of the bounds:
|
|
|
|
```dart
|
|
class A<E extends num> {}
|
|
|
|
var a = A<int>();
|
|
```
|
|
typeParameterReferencedByStatic:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Static members can't reference type parameters of the class."
|
|
correctionMessage: Try removing the reference to the type parameter, or making the member an instance member.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a static member references a
|
|
type parameter that is declared for the class. Type parameters only have
|
|
meaning for instances of the class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the static method
|
|
`hasType` has a reference to the type parameter `T`:
|
|
|
|
```dart
|
|
class C<T> {
|
|
static bool hasType(Object o) => o is [!T!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the member can be an instance member, then remove the keyword `static`:
|
|
|
|
```dart
|
|
class C<T> {
|
|
bool hasType(Object o) => o is T;
|
|
}
|
|
```
|
|
|
|
If the member must be a static member, then make the member be generic:
|
|
|
|
```dart
|
|
class C<T> {
|
|
static bool hasType<S>(Object o) => o is S;
|
|
}
|
|
```
|
|
|
|
Note, however, that there isn't a relationship between `T` and `S`, so this
|
|
second option changes the semantics from what was likely to be intended.
|
|
typeParameterSupertypeOfItsBound:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
Type bound: the name of the bounding type
|
|
problemMessage: "'#typeParameterName' can't be a supertype of its upper bound."
|
|
correctionMessage: "Try using a type that is the same as or a subclass of '#bound'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
See [diag.typeArgumentNotMatchingBounds].
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the bound of a type parameter
|
|
(the type following the `extends` keyword) is either directly or indirectly
|
|
the type parameter itself. Stating that the type parameter must be the same
|
|
as itself or a subtype of itself or a subtype of itself isn't helpful
|
|
because it will always be the same as itself.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the bound of `T` is
|
|
`T`:
|
|
|
|
```dart
|
|
class C<[!T!] extends T> {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the bound of `T1` is
|
|
`T2`, and the bound of `T2` is `T1`, effectively making the bound of `T1`
|
|
be `T1`:
|
|
|
|
```dart
|
|
class C<[!T1!] extends T2, T2 extends T1> {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type parameter needs to be a subclass of some type, then replace the
|
|
bound with the required type:
|
|
|
|
```dart
|
|
class C<T extends num> {}
|
|
```
|
|
|
|
If the type parameter can be any type, then remove the `extends` clause:
|
|
|
|
```dart
|
|
class C<T> {}
|
|
```
|
|
typeTestWithNonType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the type
|
|
problemMessage: "The name '#name' isn't a type and can't be used in an 'is' expression."
|
|
correctionMessage: Try correcting the name to match an existing type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the right-hand side of an `is`
|
|
or `is!` test isn't a type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the right-hand side is
|
|
a parameter, not a type:
|
|
|
|
```dart
|
|
typedef B = int Function(int);
|
|
|
|
void f(Object a, B b) {
|
|
if (a is [!b!]) {
|
|
return;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended to use a type test, then replace the right-hand side with a
|
|
type:
|
|
|
|
```dart
|
|
typedef B = int Function(int);
|
|
|
|
void f(Object a, B b) {
|
|
if (a is B) {
|
|
return;
|
|
}
|
|
}
|
|
```
|
|
|
|
If you intended to use a different kind of test, then change the test:
|
|
|
|
```dart
|
|
typedef B = int Function(int);
|
|
|
|
void f(Object a, B b) {
|
|
if (a == b) {
|
|
return;
|
|
}
|
|
}
|
|
```
|
|
typeTestWithUndefinedName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the type
|
|
problemMessage: "The name '#name' isn't defined, so it can't be used in an 'is' expression."
|
|
correctionMessage: "Try changing the name to the name of an existing type, or creating a type with the name '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the name following the `is` in a
|
|
type test expression isn't defined.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `Srting` isn't
|
|
defined:
|
|
|
|
```dart
|
|
void f(Object o) {
|
|
if (o is [!Srting!]) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the name with the name of a type:
|
|
|
|
```dart
|
|
void f(Object o) {
|
|
if (o is String) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
uncheckedUseOfNullableValueInSpread:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "A nullable expression can't be used in a spread."
|
|
correctionMessage: "Try checking that the value isn't 'null' before using it in a spread, or use a null-aware spread."
|
|
hasPublishedDocs: true
|
|
uncheckedInvocationOfNullableValue:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "The function can't be unconditionally invoked because it can be 'null'."
|
|
correctionMessage: "Try adding a null check ('!')."
|
|
hasPublishedDocs: true
|
|
uncheckedMethodInvocationOfNullableValue:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the method
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "The method '#name' can't be unconditionally invoked because the receiver can be 'null'."
|
|
correctionMessage: "Try making the call conditional (using '?.') or adding a null check to the target ('!')."
|
|
hasPublishedDocs: true
|
|
uncheckedOperatorInvocationOfNullableValue:
|
|
type: compileTimeError
|
|
parameters:
|
|
String operator: the name of the operator
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "The operator '#operator' can't be unconditionally invoked because the receiver can be 'null'."
|
|
correctionMessage: "Try adding a null check to the target ('!')."
|
|
hasPublishedDocs: true
|
|
uncheckedUseOfNullableValueInYieldEach:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "A nullable expression can't be used in a yield-each statement."
|
|
correctionMessage: "Try checking that the value isn't 'null' before using it in a yield-each statement."
|
|
hasPublishedDocs: true
|
|
uncheckedUseOfNullableValueAsCondition:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "A nullable expression can't be used as a condition."
|
|
correctionMessage: "Try checking that the value isn't 'null' before using it as a condition."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an expression whose type is
|
|
[potentially non-nullable][] is dereferenced without first verifying that
|
|
the value isn't `null`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `s` can be `null` at
|
|
the point where it's referenced:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if (s.[!length!] > 3) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the value really can be `null`, then add a test to ensure that members
|
|
are only accessed when the value isn't `null`:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if (s != null && s.length > 3) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
If the expression is a variable and the value should never be `null`, then
|
|
change the type of the variable to be non-nullable:
|
|
|
|
```dart
|
|
void f(String s) {
|
|
if (s.length > 3) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
If you believe that the value of the expression should never be `null`, but
|
|
you can't change the type of the variable, and you're willing to risk
|
|
having an exception thrown at runtime if you're wrong, then you can assert
|
|
that the value isn't null:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if (s!.length > 3) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
uncheckedUseOfNullableValueAsIterator:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "A nullable expression can't be used as an iterator in a for-in loop."
|
|
correctionMessage: "Try checking that the value isn't 'null' before using it as an iterator."
|
|
hasPublishedDocs: true
|
|
uncheckedPropertyAccessOfNullableValue:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the property
|
|
sharedName: uncheckedUseOfNullableValue
|
|
problemMessage: "The property '#name' can't be unconditionally accessed because the receiver can be 'null'."
|
|
correctionMessage: "Try making the access conditional (using '?.') or adding a null check to the target ('!')."
|
|
hasPublishedDocs: true
|
|
undefinedAnnotation:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the annotation
|
|
problemMessage: "Undefined name '#name' used as an annotation."
|
|
correctionMessage: Try defining the name or importing it from another library.
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name that isn't defined is
|
|
used as an annotation.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `undefined`
|
|
isn't defined:
|
|
|
|
```dart
|
|
[!@undefined!]
|
|
void f() {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name is correct, but it isn't declared yet, then declare the name as
|
|
a constant value:
|
|
|
|
```dart
|
|
const undefined = 'undefined';
|
|
|
|
@undefined
|
|
void f() {}
|
|
```
|
|
|
|
If the name is wrong, replace the name with the name of a valid constant:
|
|
|
|
```dart
|
|
@deprecated
|
|
void f() {}
|
|
```
|
|
|
|
Otherwise, remove the annotation.
|
|
undefinedClass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the undefined class
|
|
problemMessage: "Undefined class '#name'."
|
|
correctionMessage: "Try changing the name to the name of an existing class, or creating a class with the name '#name'."
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier that
|
|
appears to be the name of a class but either isn't defined or isn't visible
|
|
in the scope in which it's being referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `Piont` isn't defined:
|
|
|
|
```dart
|
|
class Point {}
|
|
|
|
void f([!Piont!] p) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the identifier isn't defined, then either define it or replace it with
|
|
the name of a class that is defined. The example above can be corrected by
|
|
fixing the spelling of the class:
|
|
|
|
```dart
|
|
class Point {}
|
|
|
|
void f(Point p) {}
|
|
```
|
|
|
|
If the class is defined but isn't visible, then you probably need to add an
|
|
import.
|
|
undefinedClassBoolean:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the undefined class
|
|
sharedName: undefinedClass
|
|
problemMessage: "Undefined class '#name'."
|
|
correctionMessage: "Try using the type 'bool'."
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Same as [diag.undefinedClass], but to catch using
|
|
"boolean" instead of "bool" in order to improve the correction message.
|
|
undefinedConstructorInInitializer:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type that does not define the invoked constructor
|
|
String constructorName: the name of the constructor being invoked
|
|
problemMessage: "The class '#type' doesn't have a constructor named '#constructorName'."
|
|
correctionMessage: "Try defining a constructor named '#constructorName' in '#type', or invoking a different constructor."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a superclass constructor is
|
|
invoked in the initializer list of a constructor, but the superclass
|
|
doesn't define the constructor being invoked.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `A` doesn't have an
|
|
unnamed constructor:
|
|
|
|
```dart
|
|
class A {
|
|
A.n();
|
|
}
|
|
class B extends A {
|
|
B() : [!super()!];
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `A` doesn't have a
|
|
constructor named `m`:
|
|
|
|
```dart
|
|
class A {
|
|
A.n();
|
|
}
|
|
class B extends A {
|
|
B() : [!super.m()!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the superclass defines a constructor that should be invoked, then change
|
|
the constructor being invoked:
|
|
|
|
```dart
|
|
class A {
|
|
A.n();
|
|
}
|
|
class B extends A {
|
|
B() : super.n();
|
|
}
|
|
```
|
|
|
|
If the superclass doesn't define an appropriate constructor, then define
|
|
the constructor being invoked:
|
|
|
|
```dart
|
|
class A {
|
|
A.m();
|
|
A.n();
|
|
}
|
|
class B extends A {
|
|
B() : super.m();
|
|
}
|
|
```
|
|
undefinedConstructorInInitializerDefault:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the superclass that does not define the invoked constructor
|
|
sharedName: undefinedConstructorInInitializer
|
|
problemMessage: "The class '#className' doesn't have an unnamed constructor."
|
|
correctionMessage: "Try defining an unnamed constructor in '#className', or invoking a different constructor."
|
|
hasPublishedDocs: true
|
|
undefinedEnumConstant:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the enum value that is not defined
|
|
Type type: the type of the enum used to access the constant
|
|
problemMessage: "There's no constant named '#memberName' in '#type'."
|
|
correctionMessage: "Try correcting the name to the name of an existing constant, or defining a constant named '#memberName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier
|
|
that appears to be the name of an enum value, and the name either isn't
|
|
defined or isn't visible in the scope in which it's being referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `E` doesn't define a
|
|
constant named `c`:
|
|
|
|
```dart
|
|
enum E {a, b}
|
|
|
|
var e = E.[!c!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the constant should be defined, then add it to the declaration of the
|
|
enum:
|
|
|
|
```dart
|
|
enum E {a, b, c}
|
|
|
|
var e = E.c;
|
|
```
|
|
|
|
If the constant shouldn't be defined, then change the name to the name of
|
|
an existing constant:
|
|
|
|
```dart
|
|
enum E {a, b}
|
|
|
|
var e = E.b;
|
|
```
|
|
undefinedEnumConstructorNamed:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the constructor that is undefined
|
|
sharedName: undefinedEnumConstructor
|
|
problemMessage: The enum doesn't have a constructor named '#name'.
|
|
correctionMessage: Try correcting the name to the name of an existing constructor, or defining constructor with the name '#name'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the constructor invoked to
|
|
initialize an enum value doesn't exist.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the enum value `c`
|
|
is being initialized by the unnamed constructor, but there's no unnamed
|
|
constructor defined in `E`:
|
|
|
|
```dart
|
|
enum E {
|
|
[!c!]();
|
|
|
|
const E.x();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the enum value `c` is
|
|
being initialized by the constructor named `x`, but there's no constructor
|
|
named `x` defined in `E`:
|
|
|
|
```dart
|
|
enum E {
|
|
c.[!x!]();
|
|
|
|
const E.y();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the enum value is being initialized by the unnamed constructor and one
|
|
of the named constructors should have been used, then add the name of the
|
|
constructor:
|
|
|
|
```dart
|
|
enum E {
|
|
c.x();
|
|
|
|
const E.x();
|
|
}
|
|
```
|
|
|
|
If the enum value is being initialized by the unnamed constructor and none
|
|
of the named constructors are appropriate, then define the unnamed
|
|
constructor:
|
|
|
|
```dart
|
|
enum E {
|
|
c();
|
|
|
|
const E();
|
|
}
|
|
```
|
|
|
|
If the enum value is being initialized by a named constructor and one of
|
|
the existing constructors should have been used, then change the name of
|
|
the constructor being invoked (or remove it if the unnamed constructor
|
|
should be used):
|
|
|
|
```dart
|
|
enum E {
|
|
c.y();
|
|
|
|
const E();
|
|
const E.y();
|
|
}
|
|
```
|
|
|
|
If the enum value is being initialized by a named constructor and none of
|
|
the existing constructors should have been used, then define a constructor
|
|
with the name that was used:
|
|
|
|
```dart
|
|
enum E {
|
|
c.x();
|
|
|
|
const E.x();
|
|
}
|
|
```
|
|
undefinedEnumConstructorUnnamed:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: undefinedEnumConstructor
|
|
problemMessage: The enum doesn't have an unnamed constructor.
|
|
correctionMessage: Try adding the name of an existing constructor, or defining an unnamed constructor.
|
|
hasPublishedDocs: true
|
|
undefinedExtensionGetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String getterName: the name of the getter that is undefined
|
|
String extensionName: the name of the extension that was explicitly specified
|
|
problemMessage: "The getter '#getterName' isn't defined for the extension '#extensionName'."
|
|
correctionMessage: "Try correcting the name to the name of an existing getter, or defining a getter named '#getterName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is used to
|
|
invoke a getter, but the getter isn't defined by the specified extension.
|
|
The analyzer also produces this diagnostic when a static getter is
|
|
referenced but isn't defined by the specified extension.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't declare an instance getter named `b`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String get a => 'a';
|
|
}
|
|
|
|
extension F on String {
|
|
String get b => 'b';
|
|
}
|
|
|
|
void f() {
|
|
E('c').[!b!];
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't declare a static getter named `a`:
|
|
|
|
```dart
|
|
extension E on String {}
|
|
|
|
var x = E.[!a!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name of the getter is incorrect, then change it to the name of an
|
|
existing getter:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String get a => 'a';
|
|
}
|
|
|
|
extension F on String {
|
|
String get b => 'b';
|
|
}
|
|
|
|
void f() {
|
|
E('c').a;
|
|
}
|
|
```
|
|
|
|
If the name of the getter is correct but the name of the extension is
|
|
wrong, then change the name of the extension to the correct name:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String get a => 'a';
|
|
}
|
|
|
|
extension F on String {
|
|
String get b => 'b';
|
|
}
|
|
|
|
void f() {
|
|
F('c').b;
|
|
}
|
|
```
|
|
|
|
If the name of the getter and extension are both correct, but the getter
|
|
isn't defined, then define the getter:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String get a => 'a';
|
|
String get b => 'z';
|
|
}
|
|
|
|
extension F on String {
|
|
String get b => 'b';
|
|
}
|
|
|
|
void f() {
|
|
E('c').b;
|
|
}
|
|
```
|
|
undefinedExtensionMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the method that is undefined
|
|
String extensionName: the name of the extension that was explicitly specified
|
|
problemMessage: "The method '#methodName' isn't defined for the extension '#extensionName'."
|
|
correctionMessage: "Try correcting the name to the name of an existing method, or defining a method named '#methodName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is used to
|
|
invoke a method, but the method isn't defined by the specified extension.
|
|
The analyzer also produces this diagnostic when a static method is
|
|
referenced but isn't defined by the specified extension.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't declare an instance method named `b`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String a() => 'a';
|
|
}
|
|
|
|
extension F on String {
|
|
String b() => 'b';
|
|
}
|
|
|
|
void f() {
|
|
E('c').[!b!]();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't declare a static method named `a`:
|
|
|
|
```dart
|
|
extension E on String {}
|
|
|
|
var x = E.[!a!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name of the method is incorrect, then change it to the name of an
|
|
existing method:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String a() => 'a';
|
|
}
|
|
|
|
extension F on String {
|
|
String b() => 'b';
|
|
}
|
|
|
|
void f() {
|
|
E('c').a();
|
|
}
|
|
```
|
|
|
|
If the name of the method is correct, but the name of the extension is
|
|
wrong, then change the name of the extension to the correct name:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String a() => 'a';
|
|
}
|
|
|
|
extension F on String {
|
|
String b() => 'b';
|
|
}
|
|
|
|
void f() {
|
|
F('c').b();
|
|
}
|
|
```
|
|
|
|
If the name of the method and extension are both correct, but the method
|
|
isn't defined, then define the method:
|
|
|
|
```dart
|
|
extension E on String {
|
|
String a() => 'a';
|
|
String b() => 'z';
|
|
}
|
|
|
|
extension F on String {
|
|
String b() => 'b';
|
|
}
|
|
|
|
void f() {
|
|
E('c').b();
|
|
}
|
|
```
|
|
undefinedExtensionOperator:
|
|
type: compileTimeError
|
|
parameters:
|
|
String operator: the name of the operator that is undefined
|
|
String extensionName: the name of the extension that was explicitly specified
|
|
problemMessage: "The operator '#operator' isn't defined for the extension '#extensionName'."
|
|
correctionMessage: "Try defining the operator '#operator'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an operator is invoked on a
|
|
specific extension when that extension doesn't implement the operator.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't define the operator `*`:
|
|
|
|
```dart
|
|
var x = E('') [!*!] 4;
|
|
|
|
extension E on String {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the extension is expected to implement the operator, then add an
|
|
implementation of the operator to the extension:
|
|
|
|
```dart
|
|
var x = E('') * 4;
|
|
|
|
extension E on String {
|
|
int operator *(int multiplier) => length * multiplier;
|
|
}
|
|
```
|
|
|
|
If the operator is defined by a different extension, then change the name
|
|
of the extension to the name of the one that defines the operator.
|
|
|
|
If the operator is defined on the argument of the extension override, then
|
|
remove the extension override:
|
|
|
|
```dart
|
|
var x = '' * 4;
|
|
|
|
extension E on String {}
|
|
```
|
|
undefinedExtensionSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String setterName: the name of the setter that is undefined
|
|
String extensionName: the name of the extension that was explicitly specified
|
|
problemMessage: "The setter '#setterName' isn't defined for the extension '#extensionName'."
|
|
correctionMessage: "Try correcting the name to the name of an existing setter, or defining a setter named '#setterName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension override is used to
|
|
invoke a setter, but the setter isn't defined by the specified extension.
|
|
The analyzer also produces this diagnostic when a static setter is
|
|
referenced but isn't defined by the specified extension.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't declare an instance setter named `b`:
|
|
|
|
```dart
|
|
extension E on String {
|
|
set a(String v) {}
|
|
}
|
|
|
|
extension F on String {
|
|
set b(String v) {}
|
|
}
|
|
|
|
void f() {
|
|
E('c').[!b!] = 'd';
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the extension `E`
|
|
doesn't declare a static setter named `a`:
|
|
|
|
```dart
|
|
extension E on String {}
|
|
|
|
void f() {
|
|
E.[!a!] = 3;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name of the setter is incorrect, then change it to the name of an
|
|
existing setter:
|
|
|
|
```dart
|
|
extension E on String {
|
|
set a(String v) {}
|
|
}
|
|
|
|
extension F on String {
|
|
set b(String v) {}
|
|
}
|
|
|
|
void f() {
|
|
E('c').a = 'd';
|
|
}
|
|
```
|
|
|
|
If the name of the setter is correct, but the name of the extension is
|
|
wrong, then change the name of the extension to the correct name:
|
|
|
|
```dart
|
|
extension E on String {
|
|
set a(String v) {}
|
|
}
|
|
|
|
extension F on String {
|
|
set b(String v) {}
|
|
}
|
|
|
|
void f() {
|
|
F('c').b = 'd';
|
|
}
|
|
```
|
|
|
|
If the name of the setter and extension are both correct, but the setter
|
|
isn't defined, then define the setter:
|
|
|
|
```dart
|
|
extension E on String {
|
|
set a(String v) {}
|
|
set b(String v) {}
|
|
}
|
|
|
|
extension F on String {
|
|
set b(String v) {}
|
|
}
|
|
|
|
void f() {
|
|
E('c').b = 'd';
|
|
}
|
|
```
|
|
undefinedFunction:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the method that is undefined
|
|
problemMessage: "The function '#name' isn't defined."
|
|
correctionMessage: "Try importing the library that defines '#name', correcting the name to the name of an existing function, or defining a function named '#name'."
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier that
|
|
appears to be the name of a function but either isn't defined or isn't
|
|
visible in the scope in which it's being referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `emty` isn't
|
|
defined:
|
|
|
|
```dart
|
|
List<int> empty() => [];
|
|
|
|
void main() {
|
|
print([!emty!]());
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the identifier isn't defined, then either define it or replace it with
|
|
the name of a function that is defined. The example above can be corrected
|
|
by fixing the spelling of the function:
|
|
|
|
```dart
|
|
List<int> empty() => [];
|
|
|
|
void main() {
|
|
print(empty());
|
|
}
|
|
```
|
|
|
|
If the function is defined but isn't visible, then you probably need to add
|
|
an import or re-arrange your code to make the function visible.
|
|
undefinedGetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String memberName: the name of the getter
|
|
Type type: the type where the getter is being looked for
|
|
problemMessage: "The getter '#memberName' isn't defined for the type '#type'."
|
|
correctionMessage: "Try importing the library that defines '#memberName', correcting the name to the name of an existing getter, or defining a getter or field named '#memberName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier that
|
|
appears to be the name of a getter but either isn't defined or isn't
|
|
visible in the scope in which it's being referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `String` has no member
|
|
named `len`:
|
|
|
|
```dart
|
|
int f(String s) => s.[!len!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the identifier isn't defined, then either define it or replace it with
|
|
the name of a getter that is defined. The example above can be corrected by
|
|
fixing the spelling of the getter:
|
|
|
|
```dart
|
|
int f(String s) => s.length;
|
|
```
|
|
undefinedGetterOnFunctionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String getterName: the name of the getter
|
|
String functionTypeAliasName: the name of the function type alias
|
|
sharedName: undefinedGetter
|
|
problemMessage: "The getter '#getterName' isn't defined for the '#functionTypeAliasName' function type."
|
|
correctionMessage: "Try wrapping the function type alias in parentheses in order to access '#getterName' as an extension getter on 'Type'."
|
|
hasPublishedDocs: true
|
|
undefinedIdentifier:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the identifier
|
|
problemMessage: "Undefined name '#name'."
|
|
correctionMessage: Try correcting the name to one that is defined, or defining the name.
|
|
isUnresolvedIdentifier: true
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier that
|
|
either isn't defined or isn't visible in the scope in which it's being
|
|
referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `rihgt` isn't
|
|
defined:
|
|
|
|
```dart
|
|
int min(int left, int right) => left <= [!rihgt!] ? left : right;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the identifier isn't defined, then either define it or replace it with
|
|
an identifier that is defined. The example above can be corrected by
|
|
fixing the spelling of the variable:
|
|
|
|
```dart
|
|
int min(int left, int right) => left <= right ? left : right;
|
|
```
|
|
|
|
If the identifier is defined but isn't visible, then you probably need to
|
|
add an import or re-arrange your code to make the identifier visible.
|
|
undefinedIdentifierAwait:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Undefined name 'await' in function body not marked with 'async'."
|
|
correctionMessage: "Try correcting the name to one that is defined, defining the name, or adding 'async' to the enclosing function body."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the name `await` is used in a
|
|
method or function body without being declared, and the body isn't marked
|
|
with the `async` keyword. The name `await` only introduces an await
|
|
expression in an asynchronous function.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `await` is
|
|
used in the body of `f` even though the body of `f` isn't marked with the
|
|
`async` keyword:
|
|
|
|
```dart
|
|
%ignore=unused_local_variable
|
|
void f(p) { [!await!] p; }
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the keyword `async` to the function body:
|
|
|
|
```dart
|
|
void f(p) async { await p; }
|
|
```
|
|
undefinedMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the method that is undefined
|
|
String typeName: the resolved type name that the method lookup is happening on
|
|
problemMessage: "The method '#methodName' isn't defined for the type '#typeName'."
|
|
correctionMessage: "Try correcting the name to the name of an existing method, or defining a method named '#methodName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier that
|
|
appears to be the name of a method but either isn't defined or isn't
|
|
visible in the scope in which it's being referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the identifier
|
|
`removeMiddle` isn't defined:
|
|
|
|
```dart
|
|
int f(List<int> l) => l.[!removeMiddle!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the identifier isn't defined, then either define it or replace it with
|
|
the name of a method that is defined. The example above can be corrected by
|
|
fixing the spelling of the method:
|
|
|
|
```dart
|
|
int f(List<int> l) => l.removeLast();
|
|
```
|
|
undefinedMethodOnFunctionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the method
|
|
String functionTypeAliasName: the name of the function type alias
|
|
sharedName: undefinedMethod
|
|
problemMessage: "The method '#methodName' isn't defined for the '#functionTypeAliasName' function type."
|
|
correctionMessage: "Try wrapping the function type alias in parentheses in order to access '#methodName' as an extension method on 'Type'."
|
|
hasPublishedDocs: true
|
|
undefinedNamedParameter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the requested named parameter
|
|
problemMessage: "The named parameter '#name' isn't defined."
|
|
correctionMessage: "Try correcting the name to an existing named parameter's name, or defining a named parameter with the name '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function invocation
|
|
has a named argument, but the method or function being invoked doesn't
|
|
define a parameter with the same name.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `m` doesn't declare a
|
|
named parameter named `a`:
|
|
|
|
```dart
|
|
class C {
|
|
m({int? b}) {}
|
|
}
|
|
|
|
void f(C c) {
|
|
c.m([!a!]: 1);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the argument name is mistyped, then replace it with the correct name.
|
|
The example above can be fixed by changing `a` to `b`:
|
|
|
|
```dart
|
|
class C {
|
|
m({int? b}) {}
|
|
}
|
|
|
|
void f(C c) {
|
|
c.m(b: 1);
|
|
}
|
|
```
|
|
|
|
If a subclass adds a parameter with the name in question, then cast the
|
|
receiver to the subclass:
|
|
|
|
```dart
|
|
class C {
|
|
m({int? b}) {}
|
|
}
|
|
|
|
class D extends C {
|
|
m({int? a, int? b}) {}
|
|
}
|
|
|
|
void f(C c) {
|
|
(c as D).m(a: 1);
|
|
}
|
|
```
|
|
|
|
If the parameter should be added to the function, then add it:
|
|
|
|
```dart
|
|
class C {
|
|
m({int? a, int? b}) {}
|
|
}
|
|
|
|
void f(C c) {
|
|
c.m(a: 1);
|
|
}
|
|
```
|
|
undefinedOperator:
|
|
type: compileTimeError
|
|
parameters:
|
|
String operator: the name of the operator
|
|
Type type: the type where the operator is being looked for
|
|
problemMessage: "The operator '#operator' isn't defined for the type '#type'."
|
|
correctionMessage: "Try defining the operator '#operator'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a user-definable operator is
|
|
invoked on an object for which the operator isn't defined.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C` doesn't
|
|
define the operator `+`:
|
|
|
|
```dart
|
|
class C {}
|
|
|
|
C f(C c) => c [!+!] 2;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the operator should be defined for the class, then define it:
|
|
|
|
```dart
|
|
class C {
|
|
C operator +(int i) => this;
|
|
}
|
|
|
|
C f(C c) => c + 2;
|
|
```
|
|
undefinedPrefixedName:
|
|
type: compileTimeError
|
|
parameters:
|
|
String referenceName: the name of the reference
|
|
String prefixName: the name of the prefix
|
|
problemMessage: "The name '#referenceName' is being referenced through the prefix '#prefixName', but it isn't defined in any of the libraries imported using that prefix."
|
|
correctionMessage: "Try correcting the prefix or importing the library that defines '#referenceName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a prefixed identifier is found
|
|
where the prefix is valid, but the identifier isn't declared in any of the
|
|
libraries imported using that prefix.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `dart:core` doesn't
|
|
define anything named `a`:
|
|
|
|
```dart
|
|
import 'dart:core' as p;
|
|
|
|
void f() {
|
|
p.[!a!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the library in which the name is declared isn't imported yet, add an
|
|
import for the library.
|
|
|
|
If the name is wrong, then change it to one of the names that's declared in
|
|
the imported libraries.
|
|
undefinedSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String setterName: the name of the setter
|
|
Type type: the enclosing type where the setter is being looked for
|
|
problemMessage: "The setter '#setterName' isn't defined for the type '#type'."
|
|
correctionMessage: "Try importing the library that defines '#setterName', correcting the name to the name of an existing setter, or defining a setter or field named '#setterName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters an identifier that
|
|
appears to be the name of a setter but either isn't defined or isn't
|
|
visible in the scope in which the identifier is being referenced.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because there isn't a setter
|
|
named `z`:
|
|
|
|
```dart
|
|
class C {
|
|
int x = 0;
|
|
void m(int y) {
|
|
this.[!z!] = y;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the identifier isn't defined, then either define it or replace it with
|
|
the name of a setter that is defined. The example above can be corrected by
|
|
fixing the spelling of the setter:
|
|
|
|
```dart
|
|
class C {
|
|
int x = 0;
|
|
void m(int y) {
|
|
this.x = y;
|
|
}
|
|
}
|
|
```
|
|
undefinedSetterOnFunctionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String setterName: the name of the setter
|
|
String functionTypeAliasName: the name of the function type alias
|
|
sharedName: undefinedSetter
|
|
problemMessage: "The setter '#setterName' isn't defined for the '#functionTypeAliasName' function type."
|
|
correctionMessage: "Try wrapping the function type alias in parentheses in order to access '#setterName' as an extension getter on 'Type'."
|
|
hasPublishedDocs: true
|
|
undefinedSuperGetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String getterName: the name of the getter
|
|
Type type: the enclosing type where the getter is being looked for
|
|
sharedName: undefinedSuperMember
|
|
problemMessage: "The getter '#getterName' isn't defined in a superclass of '#type'."
|
|
correctionMessage: "Try correcting the name to the name of an existing getter, or defining a getter or field named '#getterName' in a superclass."
|
|
hasPublishedDocs: true
|
|
undefinedSuperMethod:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the method that is undefined
|
|
String typeName: the resolved type name that the method lookup is happening on
|
|
sharedName: undefinedSuperMember
|
|
previousName: UNDEFINED_SUPER_METHOD
|
|
problemMessage: "The method '#methodName' isn't defined in a superclass of '#typeName'."
|
|
correctionMessage: "Try correcting the name to the name of an existing method, or defining a method named '#methodName' in a superclass."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an inherited member (method,
|
|
getter, setter, or operator) is referenced using `super`, but there's no
|
|
member with that name in the superclass chain.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `Object` doesn't define
|
|
a method named `n`:
|
|
|
|
```dart
|
|
class C {
|
|
void m() {
|
|
super.[!n!]();
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `Object` doesn't define
|
|
a getter named `g`:
|
|
|
|
```dart
|
|
class C {
|
|
void m() {
|
|
super.[!g!];
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the inherited member you intend to invoke has a different name, then
|
|
make the name of the invoked member match the inherited member.
|
|
|
|
If the member you intend to invoke is defined in the same class, then
|
|
remove the `super.`.
|
|
|
|
If the member isn't defined, then either add the member to one of the
|
|
superclasses or remove the invocation.
|
|
undefinedSuperOperator:
|
|
type: compileTimeError
|
|
parameters:
|
|
String operator: the name of the operator
|
|
Type type: the type where the operator is being looked for
|
|
sharedName: undefinedSuperMember
|
|
problemMessage: "The operator '#operator' isn't defined in a superclass of '#type'."
|
|
correctionMessage: "Try defining the operator '#operator' in a superclass."
|
|
hasPublishedDocs: true
|
|
undefinedSuperSetter:
|
|
type: compileTimeError
|
|
parameters:
|
|
String setterName: the name of the setter
|
|
Type type: the enclosing type where the setter is being looked for
|
|
sharedName: undefinedSuperMember
|
|
problemMessage: "The setter '#setterName' isn't defined in a superclass of '#type'."
|
|
correctionMessage: "Try correcting the name to the name of an existing setter, or defining a setter or field named '#setterName' in a superclass."
|
|
hasPublishedDocs: true
|
|
unqualifiedReferenceToNonLocalStaticMember:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the defining type
|
|
problemMessage: Static members from supertypes must be qualified by the name of the defining type.
|
|
correctionMessage: "Try adding '#name.' before the name."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This is a specialization of [instanceAccessToStaticMember] that is used
|
|
when we are able to find the name defined in a supertype. It exists to
|
|
provide a more informative error message.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when code in one class references a
|
|
static member in a superclass without prefixing the member's name with the
|
|
name of the superclass. Static members can only be referenced without a
|
|
prefix in the class in which they're declared.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the static field `x` is
|
|
referenced in the getter `g` without prefixing it with the name of the
|
|
defining class:
|
|
|
|
```dart
|
|
class A {
|
|
static int x = 3;
|
|
}
|
|
|
|
class B extends A {
|
|
int get g => [!x!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Prefix the name of the static member with the name of the declaring class:
|
|
|
|
```dart
|
|
class A {
|
|
static int x = 3;
|
|
}
|
|
|
|
class B extends A {
|
|
int get g => A.x;
|
|
}
|
|
```
|
|
unqualifiedReferenceToStaticMemberOfExtendedType:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the defining type
|
|
problemMessage: Static members from the extended type or one of its superclasses must be qualified by the name of the defining type.
|
|
correctionMessage: "Try adding '#name.' before the name."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an undefined name is found, and
|
|
the name is the same as a static member of the extended type or one of its
|
|
superclasses.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `m` is a static member
|
|
of the extended type `C`:
|
|
|
|
```dart
|
|
class C {
|
|
static void m() {}
|
|
}
|
|
|
|
extension E on C {
|
|
void f() {
|
|
[!m!]();
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're trying to reference a static member that's declared outside the
|
|
extension, then add the name of the class or extension before the reference
|
|
to the member:
|
|
|
|
```dart
|
|
class C {
|
|
static void m() {}
|
|
}
|
|
|
|
extension E on C {
|
|
void f() {
|
|
C.m();
|
|
}
|
|
}
|
|
```
|
|
|
|
If you're referencing a member that isn't declared yet, add a declaration:
|
|
|
|
```dart
|
|
class C {
|
|
static void m() {}
|
|
}
|
|
|
|
extension E on C {
|
|
void f() {
|
|
m();
|
|
}
|
|
|
|
void m() {}
|
|
}
|
|
```
|
|
uriDoesNotExist:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uriStr: the URI pointing to a nonexistent file
|
|
problemMessage: "Target of URI doesn't exist: '#uriStr'."
|
|
correctionMessage: Try creating the file referenced by the URI, or try using a URI for a file that does exist.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import, export, or part
|
|
directive is found where the URI refers to a file that doesn't exist.
|
|
|
|
#### Examples
|
|
|
|
If the file `lib.dart` doesn't exist, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import [!'lib.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the URI was mistyped or invalid, then correct the URI.
|
|
|
|
If the URI is correct, then create the file.
|
|
uriHasNotBeenGenerated:
|
|
type: compileTimeError
|
|
parameters:
|
|
String uriStr: the URI pointing to a nonexistent file
|
|
problemMessage: "Target of URI hasn't been generated: '#uriStr'."
|
|
correctionMessage: Try running the generator that will generate the file referenced by the URI.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import, export, or part
|
|
directive is found where the URI refers to a file that doesn't exist and
|
|
the name of the file ends with a pattern that's commonly produced by code
|
|
generators, such as one of the following:
|
|
- `.g.dart`
|
|
- `.pb.dart`
|
|
- `.pbenum.dart`
|
|
- `.pbserver.dart`
|
|
- `.pbjson.dart`
|
|
- `.template.dart`
|
|
|
|
#### Example
|
|
|
|
If the file `lib.g.dart` doesn't exist, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import [!'lib.g.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the file is a generated file, then run the generator that generates the
|
|
file.
|
|
|
|
If the file isn't a generated file, then check the spelling of the URI or
|
|
create the file.
|
|
uriWithInterpolation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "URIs can't use string interpolation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the string literal in an
|
|
`import`, `export`, or `part` directive contains an interpolation. The
|
|
resolution of the URIs in directives must happen before the declarations
|
|
are compiled, so expressions can't be evaluated while determining the
|
|
values of the URIs.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the string in the
|
|
`import` directive contains an interpolation:
|
|
|
|
```dart
|
|
import [!'dart:$m'!];
|
|
|
|
const m = 'math';
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the interpolation from the URI:
|
|
|
|
```dart
|
|
import 'dart:math';
|
|
|
|
var zero = min(0, 0);
|
|
```
|
|
useOfNativeExtension:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Dart native extensions are deprecated and aren't available in Dart 2.15.
|
|
correctionMessage: "Try using dart:ffi for C interop."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library is imported using the
|
|
`dart-ext` scheme.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the native library `x`
|
|
is being imported using a scheme of `dart-ext`:
|
|
|
|
```dart
|
|
import [!'dart-ext:x'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rewrite the code to use `dart:ffi` as a way of invoking the contents of the
|
|
native library.
|
|
useOfPrivateParameterName:
|
|
type: compileTimeError
|
|
sharedName: undefinedNamedParameter
|
|
parameters:
|
|
String name: the public name of the requested named parameter
|
|
problemMessage: "The named parameter '_#name' should use the corresponding public name '#name' at the callsite."
|
|
correctionMessage: "Try changing the name to '#name'."
|
|
hasPublishedDocs: true
|
|
useOfVoidResult:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "This expression has a type of 'void' so its value can't be used."
|
|
correctionMessage: "Try checking to see if you're using the correct API; there might be a function or call that returns void you didn't expect. Also check type parameters and variables which might also be void."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds an expression whose
|
|
type is `void`, and the expression is used in a place where a value is
|
|
expected, such as before a member access or on the right-hand side of an
|
|
assignment.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` doesn't produce an
|
|
object on which `toString` can be invoked:
|
|
|
|
```dart
|
|
void f() {}
|
|
|
|
void g() {
|
|
[!f()!].toString();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Either rewrite the code so that the expression has a value or rewrite the
|
|
code so that it doesn't depend on the value.
|
|
valuesDeclarationInEnum:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: A member named 'values' can't be declared in an enum.
|
|
correctionMessage: Try using a different name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enum declaration defines a
|
|
member named `values`, whether the member is an enum value, an instance
|
|
member, or a static member.
|
|
|
|
Any such member conflicts with the implicit declaration of the static
|
|
getter named `values` that returns a list containing all the enum
|
|
constants.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum `E` defines
|
|
an instance member named `values`:
|
|
|
|
```dart
|
|
enum E {
|
|
v;
|
|
void [!values!]() {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the name of the conflicting member:
|
|
|
|
```dart
|
|
enum E {
|
|
v;
|
|
void getValues() {}
|
|
}
|
|
```
|
|
variableTypeMismatch:
|
|
type: compileTimeError
|
|
parameters:
|
|
String valueType: the type of the object being assigned.
|
|
String variableType: the type of the variable being assigned to
|
|
problemMessage: "A value of type '#valueType' can't be assigned to a const variable of type '#variableType'."
|
|
correctionMessage: "Try using a subtype, or removing the 'const' keyword"
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the evaluation of a constant
|
|
expression would result in a `CastException`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of `x` is an
|
|
`int`, which can't be assigned to `y` because an `int` isn't a `String`:
|
|
|
|
```dart
|
|
const dynamic x = 0;
|
|
const String y = [!x!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the declaration of the constant is correct, then change the value being
|
|
assigned to be of the correct type:
|
|
|
|
```dart
|
|
const dynamic x = 0;
|
|
const String y = '$x';
|
|
```
|
|
|
|
If the assigned value is correct, then change the declaration to have the
|
|
correct type:
|
|
|
|
```dart
|
|
const int x = 0;
|
|
const int y = x;
|
|
```
|
|
wrongExplicitTypeParameterVarianceInSuperinterface:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
String varianceModifier: the variance modifier defined for the type parameter
|
|
String variancePosition: the variance position of the type parameter in the superinterface
|
|
Type superInterface: the type of the superinterface
|
|
problemMessage: "'#typeParameterName' is an '#varianceModifier' type parameter and can't be used in an '#variancePosition' position in '#superInterface'."
|
|
correctionMessage: "Try using 'in' type parameters in 'in' positions and 'out' type parameters in 'out' positions in the superinterface."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
Let `C` be a generic class that declares a formal type parameter `X`, and
|
|
assume that `T` is a direct superinterface of `C`.
|
|
|
|
It is a compile-time error if `X` is explicitly defined as a covariant or
|
|
'in' type parameter and `X` occurs in a non-covariant position in `T`.
|
|
It is a compile-time error if `X` is explicitly defined as a contravariant
|
|
or 'out' type parameter and `X` occurs in a non-contravariant position in
|
|
`T`.
|
|
wrongNumberOfParametersForOperator:
|
|
type: compileTimeError
|
|
parameters:
|
|
String name: the name of the declared operator
|
|
int expectedCount: the number of parameters expected
|
|
int actualCount: the number of parameters found in the operator declaration
|
|
problemMessage: "Operator '#name' should declare exactly #expectedCount parameters, but #actualCount found."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a declaration of an operator has
|
|
the wrong number of parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the operator `+` must
|
|
have a single parameter corresponding to the right operand:
|
|
|
|
```dart
|
|
class C {
|
|
int operator [!+!](a, b) => 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add or remove parameters to match the required number:
|
|
|
|
```dart
|
|
class C {
|
|
int operator +(a) => 0;
|
|
}
|
|
```
|
|
TODO(brianwilkerson): It would be good to add a link to the spec or some
|
|
other documentation that lists the number of parameters for each
|
|
operator, but I don't know what to link to.
|
|
TODO(brianwilkerson): Another reasonable fix is to convert the operator to
|
|
be a normal method.
|
|
wrongNumberOfParametersForOperatorMinus:
|
|
type: compileTimeError
|
|
parameters:
|
|
int actualCount: the number of parameters found in the operator declaration
|
|
sharedName: wrongNumberOfParametersForOperator
|
|
problemMessage: "Operator '-' should declare 0 or 1 parameter, but #actualCount found."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
7.1.1 Operators: It is a compile time error if the arity of the
|
|
user-declared operator - is not 0 or 1.
|
|
wrongNumberOfTypeArguments:
|
|
type: compileTimeError
|
|
parameters:
|
|
String type: the name of the type being referenced
|
|
int typeParameterCount: the number of type parameters that were declared
|
|
int typeArgumentCount: the number of type arguments provided
|
|
problemMessage: "The type '#type' is declared with #typeParameterCount type parameters, but #typeArgumentCount type arguments were given."
|
|
correctionMessage: Try adjusting the number of type arguments to match the number of type parameters.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a type that has type parameters
|
|
is used and type arguments are provided, but the number of type arguments
|
|
isn't the same as the number of type parameters.
|
|
|
|
The analyzer also produces this diagnostic when a constructor is invoked
|
|
and the number of type arguments doesn't match the number of type
|
|
parameters declared for the class.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `C` has one type
|
|
parameter but two type arguments are provided when it is used as a type
|
|
annotation:
|
|
|
|
```dart
|
|
class C<E> {}
|
|
|
|
void f([!C<int, int>!] x) {}
|
|
```
|
|
|
|
The following code produces this diagnostic because `C` declares one type
|
|
parameter, but two type arguments are provided when creating an instance:
|
|
|
|
```dart
|
|
class C<E> {}
|
|
|
|
var c = [!C<int, int>!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add or remove type arguments, as necessary, to match the number of type
|
|
parameters defined for the type:
|
|
|
|
```dart
|
|
class C<E> {}
|
|
|
|
void f(C<int> x) {}
|
|
```
|
|
wrongNumberOfTypeArgumentsConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class being instantiated
|
|
String constructorName: the name of the constructor being invoked
|
|
problemMessage: "The constructor '#className.#constructorName' doesn't have type parameters."
|
|
correctionMessage: Try moving type arguments to after the type name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when type arguments are provided
|
|
after the name of a named constructor. Constructors can't declare type
|
|
parameters, so invocations can only provide the type arguments associated
|
|
with the class, and those type arguments are required to follow the name of
|
|
the class rather than the name of the constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type parameters
|
|
(`<String>`) follow the name of the constructor rather than the name of the
|
|
class:
|
|
|
|
```dart
|
|
class C<T> {
|
|
C.named();
|
|
}
|
|
C f() => C.named[!<String>!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type arguments are for the class' type parameters, then move the
|
|
type arguments to follow the class name:
|
|
|
|
```dart
|
|
class C<T> {
|
|
C.named();
|
|
}
|
|
C f() => C<String>.named();
|
|
```
|
|
|
|
If the type arguments aren't for the class' type parameters, then remove
|
|
them:
|
|
|
|
```dart
|
|
class C<T> {
|
|
C.named();
|
|
}
|
|
C f() => C.named();
|
|
```
|
|
wrongNumberOfTypeArgumentsDotShorthandConstructor:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the class being instantiated
|
|
String constructorName: the name of the constructor being invoked
|
|
sharedName: wrongNumberOfTypeArgumentsConstructor
|
|
problemMessage: "The dot shorthand resolves to the constructor '#className.#constructorName', and type parameters can't be applied to dot shorthand constructor invocations."
|
|
correctionMessage: Try removing the type arguments, or adding a class name, followed by the type arguments, then the constructor name.
|
|
hasPublishedDocs: true
|
|
wrongNumberOfTypeArgumentsEnum:
|
|
type: compileTimeError
|
|
parameters:
|
|
int typeParameterCount: the number of type parameters that were declared
|
|
int typeArgumentCount: the number of type arguments provided
|
|
problemMessage: "The enum is declared with #typeParameterCount type parameters, but #typeArgumentCount type arguments were given."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an enum value in an enum that
|
|
has type parameters is instantiated and type arguments are provided, but
|
|
the number of type arguments isn't the same as the number of type
|
|
parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum value `c`
|
|
provides one type argument even though the enum `E` is declared to have
|
|
two type parameters:
|
|
|
|
```dart
|
|
enum E<T, U> {
|
|
c[!<int>!]()
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the number of type parameters is correct, then change the number of
|
|
type arguments to match the number of type parameters:
|
|
|
|
```dart
|
|
enum E<T, U> {
|
|
c<int, String>()
|
|
}
|
|
```
|
|
|
|
If the number of type arguments is correct, then change the number of type
|
|
parameters to match the number of type arguments:
|
|
|
|
```dart
|
|
enum E<T> {
|
|
c<int>()
|
|
}
|
|
```
|
|
wrongNumberOfTypeArgumentsExtension:
|
|
type: compileTimeError
|
|
parameters:
|
|
String extensionName: the name of the extension being referenced
|
|
int typeParameterCount: the number of type parameters that were declared
|
|
int typeArgumentCount: the number of type arguments provided
|
|
problemMessage: "The extension '#extensionName' is declared with #typeParameterCount type parameters, but #typeArgumentCount type arguments were given."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension that has type
|
|
parameters is used and type arguments are provided, but the number of type
|
|
arguments isn't the same as the number of type parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the extension `E` is
|
|
declared to have a single type parameter (`T`), but the extension override
|
|
has two type arguments:
|
|
|
|
```dart
|
|
extension E<T> on List<T> {
|
|
int get len => length;
|
|
}
|
|
|
|
void f(List<int> p) {
|
|
E[!<int, String>!](p).len;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the type arguments so that there are the same number of type
|
|
arguments as there are type parameters:
|
|
|
|
```dart
|
|
extension E<T> on List<T> {
|
|
int get len => length;
|
|
}
|
|
|
|
void f(List<int> p) {
|
|
E<int>(p).len;
|
|
}
|
|
```
|
|
wrongNumberOfTypeArgumentsFunction:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the function type
|
|
int typeParameterCount: the number of type parameters that were declared
|
|
int typeArgumentCount: the number of type arguments provided
|
|
sharedName: wrongNumberOfTypeArgumentsFunction
|
|
problemMessage: "The type of this function is '#type', which has #typeParameterCount type parameters, but #typeArgumentCount type arguments were given."
|
|
correctionMessage: Try adjusting the number of type arguments to match the number of type parameters.
|
|
hasPublishedDocs: false
|
|
wrongNumberOfTypeArgumentsElement:
|
|
type: compileTimeError
|
|
parameters:
|
|
String kind: the name of the kind of the element being referenced
|
|
String element: the name of the element being referenced
|
|
int typeParameterCount: the number of type parameters that were declared
|
|
int typeArgumentCount: the number of type arguments provided
|
|
problemMessage: "The #kind '#element' is declared with #typeParameterCount type parameters, but #typeArgumentCount type arguments are given."
|
|
correctionMessage: Try adjusting the number of type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function is invoked
|
|
with a different number of type arguments than the number of type
|
|
parameters specified in its declaration. There must either be no type
|
|
arguments or the number of arguments must match the number of parameters.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the invocation of the
|
|
method `m` has two type arguments, but the declaration of `m` only has one
|
|
type parameter:
|
|
|
|
```dart
|
|
class C {
|
|
int m<A>(A a) => 0;
|
|
}
|
|
|
|
int f(C c) => c.m[!<int, int>!](2);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type arguments are necessary, then make them match the number of
|
|
type parameters by either adding or removing type arguments:
|
|
|
|
```dart
|
|
class C {
|
|
int m<A>(A a) => 0;
|
|
}
|
|
|
|
int f(C c) => c.m<int>(2);
|
|
```
|
|
|
|
If the type arguments aren't necessary, then remove them:
|
|
|
|
```dart
|
|
class C {
|
|
int m<A>(A a) => 0;
|
|
}
|
|
|
|
int f(C c) => c.m(2);
|
|
```
|
|
wrongTypeParameterVarianceInSuperinterface:
|
|
type: compileTimeError
|
|
parameters:
|
|
String typeParameterName: the name of the type parameter
|
|
Type superInterfaceType: the name of the super interface
|
|
problemMessage: "'#typeParameterName' can't be used contravariantly or invariantly in '#superInterfaceType'."
|
|
correctionMessage: Try not using class type parameters in types of formal parameters of function types, nor in explicitly contravariant or invariant superinterfaces.
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
Let `C` be a generic class that declares a formal type parameter `X`, and
|
|
assume that `T` is a direct superinterface of `C`. It is a compile-time
|
|
error if `X` occurs contravariantly or invariantly in `T`.
|
|
wrongTypeParameterVariancePosition:
|
|
type: compileTimeError
|
|
parameters:
|
|
String modifier: the variance modifier
|
|
String typeParameterName: the name of the type parameter
|
|
String variancePosition: the variance position that the type parameter is in
|
|
problemMessage: "The '#modifier' type parameter '#typeParameterName' can't be used in an '#variancePosition' position."
|
|
correctionMessage: "Try removing the type parameter or change the explicit variance modifier declaration for the type parameter to another one of 'in', 'out', or 'inout'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
Let `C` be a generic class that declares a formal type parameter `X`.
|
|
|
|
If `X` is explicitly contravariant then it is a compile-time error for
|
|
`X` to occur in a non-contravariant position in a member signature in the
|
|
body of `C`, except when `X` is in a contravariant position in the type
|
|
annotation of a covariant formal parameter.
|
|
|
|
If `X` is explicitly covariant then it is a compile-time error for
|
|
`X` to occur in a non-covariant position in a member signature in the
|
|
body of `C`, except when `X` is in a covariant position in the type
|
|
annotation of a covariant formal parameter.
|
|
yieldEachInNonGenerator:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: yieldInNonGenerator
|
|
problemMessage: "Yield-each statements must be in a generator function (one marked with either 'async*' or 'sync*')."
|
|
correctionMessage: "Try adding 'async*' or 'sync*' to the enclosing function."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `yield` or `yield*` statement
|
|
appears in a function whose body isn't marked with one of the `async*` or
|
|
`sync*` modifiers.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `yield` is being used
|
|
in a function whose body doesn't have a modifier:
|
|
|
|
```dart
|
|
Iterable<int> get digits {
|
|
yield* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `yield*` is being used
|
|
in a function whose body has the `async` modifier rather than the `async*`
|
|
modifier:
|
|
|
|
```dart
|
|
%ignore=illegal_async_return_type
|
|
Stream<int> get digits async {
|
|
[!yield* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add a modifier, or change the existing modifier to be either `async*` or
|
|
`sync*`:
|
|
|
|
```dart
|
|
Iterable<int> get digits sync* {
|
|
yield* [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
}
|
|
```
|
|
yieldInNonGenerator:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Yield statements must be in a generator function (one marked with either 'async*' or 'sync*')."
|
|
correctionMessage: "Try adding 'async*' or 'sync*' to the enclosing function."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
?? Yield: It is a compile-time error if a yield statement appears in a
|
|
function that is not a generator function.
|
|
yieldEachOfInvalidType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the type of the expression after `yield*`
|
|
Type expectedType: the return type of the function containing the `yield*`
|
|
sharedName: yieldOfInvalidType
|
|
problemMessage: "The type '#actualType' implied by the 'yield*' expression must be assignable to '#expectedType'."
|
|
hasPublishedDocs: true
|
|
yieldOfInvalidType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type actualType: the type of the expression after `yield`
|
|
Type expectedType: the return type of the function containing the `yield`
|
|
problemMessage: "A yielded value of type '#actualType' must be assignable to '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type of object produced by
|
|
a `yield` or `yield*` expression doesn't match the type of objects that
|
|
are to be returned from the `Iterable` or `Stream` types that are returned
|
|
from a generator (a function or method marked with either `sync*` or
|
|
`async*`).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the getter `zero` is
|
|
declared to return an `Iterable` that returns integers, but the `yield` is
|
|
returning a string from the iterable:
|
|
|
|
```dart
|
|
Iterable<int> get zero sync* {
|
|
yield [!'0'!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the return type of the function is correct, then fix the expression
|
|
following the keyword `yield` to return the correct type:
|
|
|
|
```dart
|
|
Iterable<int> get zero sync* {
|
|
yield 0;
|
|
}
|
|
```
|
|
|
|
If the expression following the `yield` is correct, then change the return
|
|
type of the function to allow it:
|
|
|
|
```dart
|
|
Iterable<String> get zero sync* {
|
|
yield '0';
|
|
}
|
|
```
|
|
FfiCode:
|
|
abiSpecificIntegerInvalid:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Classes extending 'AbiSpecificInteger' must have exactly one const constructor, no other members, and no type parameters."
|
|
correctionMessage: Try removing all type parameters, removing all members, and adding one const constructor.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that extends
|
|
`AbiSpecificInteger` doesn't meet all of the following requirements:
|
|
- there must be exactly one constructor
|
|
- the constructor must be marked `const`
|
|
- there must not be any members of other than the one constructor
|
|
- there must not be any type parameters
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the class `C` doesn't
|
|
define a const constructor:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class [!C!] extends AbiSpecificInteger {
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the constructor isn't
|
|
a `const` constructor:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class [!C!] extends AbiSpecificInteger {
|
|
C();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `C` defines
|
|
multiple constructors:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class [!C!] extends AbiSpecificInteger {
|
|
const C.zero();
|
|
const C.one();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `C` defines
|
|
a field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class [!C!] extends AbiSpecificInteger {
|
|
final int i;
|
|
|
|
const C(this.i);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `C` has a
|
|
type parameter:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class [!C!]<T> extends AbiSpecificInteger { // type parameters
|
|
const C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the class so that it meets the requirements of having no type
|
|
parameters and a single member that is a `const` constructor:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class C extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
abiSpecificIntegerMappingExtra:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a 'NativeType' integer with a fixed size."
|
|
correctionMessage: Try removing the extra annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that extends
|
|
`AbiSpecificInteger` has more than one `AbiSpecificIntegerMapping`
|
|
annotation.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because there are two
|
|
`AbiSpecificIntegerMapping` annotations on the class `C`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
@[!AbiSpecificIntegerMapping!]({Abi.linuxX64 : Uint16()})
|
|
final class C extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the annotations, merging the arguments as
|
|
appropriate:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8(), Abi.linuxX64 : Uint16()})
|
|
final class C extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
abiSpecificIntegerMappingMissing:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Classes extending 'AbiSpecificInteger' must have exactly one 'AbiSpecificIntegerMapping' annotation specifying the mapping from ABI to a 'NativeType' integer with a fixed size."
|
|
correctionMessage: Try adding an annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class that extends
|
|
`AbiSpecificInteger` doesn't have an `AbiSpecificIntegerMapping`
|
|
annotation.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because there's no
|
|
`AbiSpecificIntegerMapping` annotation on the class `C`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class [!C!] extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an `AbiSpecificIntegerMapping` annotation to the class:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class C extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
abiSpecificIntegerMappingUnsupported:
|
|
type: compileTimeError
|
|
parameters:
|
|
String mappingName: the value of the invalid mapping
|
|
problemMessage: "Invalid mapping to '#mappingName'; only mappings to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', and 'Uint64' are supported."
|
|
correctionMessage: Try changing the value to 'Int8', 'Int16', 'Int32', 'Int64', 'Uint8', 'Uint16', 'UInt32', or 'Uint64'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a value in the map argument of
|
|
an `AbiSpecificIntegerMapping` annotation is anything other than one of
|
|
the following integer types:
|
|
- `Int8`
|
|
- `Int16`
|
|
- `Int32`
|
|
- `Int64`
|
|
- `Uint8`
|
|
- `Uint16`
|
|
- `UInt32`
|
|
- `Uint64`
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the map
|
|
entry is `Array<Uint8>`, which isn't a valid integer type:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : [!Array<Uint8>(4)!]})
|
|
final class C extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use one of the valid types as a value in the map:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@AbiSpecificIntegerMapping({Abi.macosX64 : Int8()})
|
|
final class C extends AbiSpecificInteger {
|
|
const C();
|
|
}
|
|
```
|
|
addressPosition:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The '.address' expression can only be used as argument to a leaf native external call."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `.address` getter is used
|
|
in a context other than as an argument to a native external call that is
|
|
marked as a leaf call (`isLeaf: true`).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `.address` is used
|
|
incorrectly:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
import 'dart:typed_data';
|
|
|
|
@Native<Void Function(Pointer<Uint8>)>()
|
|
external void nonLeafCall(Pointer<Uint8> ptr);
|
|
|
|
void main() {
|
|
final data = Uint8List(10);
|
|
|
|
// Incorrect: Using '.address' as an argument to a non-leaf call.
|
|
nonLeafCall(data.[!address!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Ensure that the `.address` expression is used directly as an argument to a
|
|
native external call that is annotated with `@Native(...)` and has
|
|
`isLeaf: true` set in its annotation.
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
import 'dart:typed_data';
|
|
|
|
@Native<Void Function(Pointer<Uint8>)>(isLeaf: true)
|
|
external void leafCall(Pointer<Uint8> ptr);
|
|
|
|
void main() {
|
|
final data = Uint8List(10);
|
|
|
|
// Correct: Using .address directly as an argument to a leaf call.
|
|
leafCall(data.address);
|
|
}
|
|
```
|
|
addressReceiver:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The receiver of '.address' must be a concrete 'TypedData', a concrete 'TypedData' '[]', an 'Array', an 'Array' '[]', a Struct field, or a Union field."
|
|
correctionMessage: Change the receiver of '.address' to one of the allowed kinds.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `.address` getter is used
|
|
on a receiver whose static type isn't one of the allowed FFI types. The
|
|
`.address` getter is used to obtain a `Pointer` to the underlying memory
|
|
of an FFI data structure.
|
|
|
|
The receiver of `.address` must be one of the following:
|
|
- A concrete `TypedData` instance (e.g., `Uint8List`).
|
|
- An element of a concrete `TypedData` instance accessed via `[]`.
|
|
- An `Array<T>` instance (from `dart:ffi`).
|
|
- An element of an `Array<T>` instance accessed via `[]`.
|
|
- A field of a `Struct` or `Union` subclass, if that field's type is `Array<T>`, a nested `Struct`, or a nested `Union`.
|
|
- A `Struct` or `Union` instance.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic for various incorrect receivers:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct extends Struct {
|
|
@Uint8()
|
|
external int x;
|
|
|
|
@Uint8()
|
|
external int y;
|
|
}
|
|
|
|
@Native<Void Function(Pointer)>(isLeaf: true)
|
|
external void nativeLeafCall(Pointer ptr);
|
|
|
|
void main() {
|
|
final struct = Struct.create<MyStruct>();
|
|
final y = struct.y;
|
|
// Incorrect: The receiver is not a struct field, but some integer.
|
|
nativeLeafCall(y.[!address!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Ensure that the receiver of the `.address` getter is one of the allowed
|
|
types. The `.address` getter is for obtaining a `Pointer` to the memory
|
|
of `TypedData`, `Array`, `Struct`, or `Union` instances, or certain
|
|
fields/elements thereof.
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Pointer)>(isLeaf: true)
|
|
external void nativeLeafCall(Pointer ptr);
|
|
|
|
final class MyStruct extends Struct {
|
|
@Uint8()
|
|
external int x;
|
|
|
|
@Uint8()
|
|
external int y;
|
|
}
|
|
|
|
void main() {
|
|
final struct = Struct.create<MyStruct>();
|
|
// Correct: The receiver is a struct field.
|
|
nativeLeafCall(struct.y.address);
|
|
}
|
|
```
|
|
annotationOnPointerField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Fields in a struct class whose type is 'Pointer' shouldn't have any annotations."
|
|
correctionMessage: Try removing the annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field that's declared in a
|
|
subclass of `Struct` and has the type `Pointer` also has an annotation
|
|
associated with it.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `p`, which
|
|
has the type `Pointer` and is declared in a subclass of `Struct`, has the
|
|
annotation `@Double()`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
[!@Double()!]
|
|
external Pointer<Int8> p;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotations from the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
external Pointer<Int8> p;
|
|
}
|
|
```
|
|
argumentMustBeAConstant:
|
|
type: compileTimeError
|
|
parameters:
|
|
String argumentName: the name of the argument
|
|
problemMessage: "Argument '#argumentName' must be a constant."
|
|
correctionMessage: Try replacing the value with a literal or const.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of either
|
|
`Pointer.asFunction` or `DynamicLibrary.lookupFunction` has an `isLeaf`
|
|
argument whose value isn't a constant expression.
|
|
|
|
The analyzer also produces this diagnostic when an invocation of either
|
|
`Pointer.fromFunction` or `NativeCallable.isolateLocal` has an
|
|
`exceptionalReturn` argument whose value isn't a constant expression.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the
|
|
`isLeaf` argument is a parameter, and hence isn't a constant:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int Function(int) fromPointer(
|
|
Pointer<NativeFunction<Int8 Function(Int8)>> p, bool isLeaf) {
|
|
return p.asFunction(isLeaf: [!isLeaf!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's a suitable constant that can be used, then replace the argument
|
|
with a constant:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
const isLeaf = false;
|
|
|
|
int Function(int) fromPointer(Pointer<NativeFunction<Int8 Function(Int8)>> p) {
|
|
return p.asFunction(isLeaf: isLeaf);
|
|
}
|
|
```
|
|
|
|
If there isn't a suitable constant, then replace the argument with a
|
|
boolean literal:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int Function(int) fromPointer(Pointer<NativeFunction<Int8 Function(Int8)>> p) {
|
|
return p.asFunction(isLeaf: true);
|
|
}
|
|
```
|
|
argumentMustBeNative:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Argument to 'Native.addressOf' must be annotated with @Native"
|
|
correctionMessage: "Try passing a static function or field annotated with '@Native'"
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the argument passed to
|
|
`Native.addressOf` isn't annotated with the `Native` annotation.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the argument to
|
|
`addressOf` is a string, not a field, and strings can't be annotated:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function()>()
|
|
external void f();
|
|
|
|
void g() {
|
|
print(Native.addressOf([!'f'!]));
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the function `f` is
|
|
being passed to `addressOf` but isn't annotated as being `Native`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
external void f();
|
|
|
|
void g() {
|
|
print(Native.addressOf<NativeFunction<Void Function()>>([!f!]));
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the argument isn't either a field or a function, then replace the
|
|
argument with a field or function that's annotated with `Native`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function()>()
|
|
external void f();
|
|
|
|
void g() {
|
|
print(Native.addressOf<NativeFunction<Void Function()>>(f));
|
|
}
|
|
```
|
|
|
|
If the argument is either a field or a function, then annotate the field
|
|
of function with `Native`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function()>()
|
|
external void f();
|
|
|
|
void g() {
|
|
print(Native.addressOf<NativeFunction<Void Function()>>(f));
|
|
}
|
|
```
|
|
nativeFieldInvalidType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: The invalid type.
|
|
problemMessage: "'#type' is an unsupported type for native fields. Native fields only support pointers, arrays or numeric and compound types."
|
|
correctionMessage: "Try changing the type in the `@Native` annotation to a numeric FFI type, a pointer, array, or a compound class."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `@Native`-annotated field
|
|
has a type not supported for native fields.
|
|
|
|
Native fields support pointers, arrays, numeric types and subtypes of
|
|
`Compound` (i.e., structs or unions). Other subtypes of `NativeType`,
|
|
such as `Handle` or `NativeFunction` are not allowed as native fields.
|
|
|
|
Native functions should be used with external functions instead of
|
|
external fields.
|
|
|
|
Handles are unsupported because there is no way to transparently load and
|
|
store Dart objects into pointers.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `free` uses
|
|
an unsupported native type, `NativeFunction`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<NativeFunction<Void Function()>>()
|
|
external void Function() [!free!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you meant to bind to an existing native function with a
|
|
`NativeFunction` field, use `@Native` methods instead:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Pointer<Void>)>()
|
|
external void free(Pointer<Void> ptr);
|
|
```
|
|
|
|
To bind to a field storing a function pointer in C, use a pointer type
|
|
for the Dart field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native()
|
|
external Pointer<NativeFunction<Void Function(Pointer<Void>)>> free;
|
|
```
|
|
nativeFieldMissingType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The native type of this field could not be inferred and must be specified in the annotation."
|
|
correctionMessage: "Try adding a type parameter extending `NativeType` to the `@Native` annotation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `@Native`-annotated field
|
|
requires a type hint on the annotation to infer the native type.
|
|
|
|
Dart types like `int` and `double` have multiple possible native
|
|
representations. Since the native type needs to be known at compile time
|
|
to generate the correct load and stores when accessing the field, an
|
|
explicit type must be given.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `f` has
|
|
the type `int` (for which multiple native representations exist), but no
|
|
explicit type parameter on the `Native` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native()
|
|
external int [!f!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
To fix this diagnostic, find out the correct native representation from
|
|
the native declaration of the field. Then, add the corresponding type to
|
|
the annotation. For instance, if `f` was declared as an `uint8_t` in C,
|
|
the Dart field should be declared as:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Uint8>()
|
|
external int f;
|
|
```
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
nativeFieldNotStatic:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Native fields must be static."
|
|
correctionMessage: "Try adding the modifier 'static' to this field."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an instance field in a class
|
|
has been annotated with `@Native`.
|
|
Native fields refer to global variables in C, C++ or other native
|
|
languages, whereas instance fields in Dart are specific to an instance of
|
|
that class. Hence, native fields must be static.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `f` in the
|
|
class `C` is `@Native`, but not `static`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class C {
|
|
@Native<Int>()
|
|
external int [!f!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Either make the field static:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class C {
|
|
@Native<Int>()
|
|
external static int f;
|
|
}
|
|
```
|
|
|
|
Or move it out of a class, in which case no explicit `static` modifier is
|
|
required:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class C {
|
|
}
|
|
|
|
@Native<Int>()
|
|
external int f;
|
|
```
|
|
|
|
If you meant to annotate an instance field that should be part of a
|
|
struct, omit the `@Native` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int()
|
|
external int f;
|
|
}
|
|
```
|
|
nativeFunctionMissingType:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The native type of this function couldn't be inferred so it must be specified in the annotation.
|
|
correctionMessage: Try adding a type parameter extending `NativeType` to the `@Native` annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `@Native`-annotated function
|
|
requires a type hint on the annotation to infer the native function type.
|
|
|
|
Dart types like `int` and `double` have multiple possible native
|
|
representations. Since the native type needs to be known at compile time
|
|
to generate correct bindings and call instructions for the function, an
|
|
explicit type must be given.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `f()` has
|
|
the return type `int`, but doesn't have an explicit type parameter on the
|
|
`Native` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native()
|
|
external int [!f!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the corresponding type to the annotation. For instance, if `f()` was
|
|
declared to return an `int32_t` in C, the Dart function should be declared
|
|
as:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Int32 Function()>()
|
|
external int f();
|
|
```
|
|
compoundImplementsFinalizable:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the struct or union class
|
|
problemMessage: "The class '#className' can't implement Finalizable."
|
|
correctionMessage: "Try removing the implements clause from '#className'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a subclass of either `Struct`
|
|
or `Union` implements `Finalizable`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `S`
|
|
implements `Finalizable`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class [!S!] extends Struct implements Finalizable {
|
|
external Pointer notEmpty;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Try removing the implements clause from the class:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class S extends Struct {
|
|
external Pointer notEmpty;
|
|
}
|
|
```
|
|
creationOfStructOrUnion:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Subclasses of 'Struct' and 'Union' are backed by native memory, and can't be instantiated by a generative constructor."
|
|
correctionMessage: "Try allocating it via allocation, or load from a 'Pointer'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a subclass of either `Struct`
|
|
or `Union` is instantiated using a generative constructor.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C` is being
|
|
instantiated using a generative constructor:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
external int a;
|
|
}
|
|
|
|
void f() {
|
|
[!C!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to allocate the structure described by the class, then use the
|
|
`ffi` package to do so:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
external int a;
|
|
}
|
|
|
|
void f() {
|
|
final pointer = calloc.allocate<C>(4);
|
|
final c = pointer.ref;
|
|
print(c);
|
|
calloc.free(pointer);
|
|
}
|
|
```
|
|
emptyStruct:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the superclass
|
|
problemMessage: "The class '#subclassName' can't be empty because it's a subclass of '#superclassName'."
|
|
correctionMessage: "Try adding a field to '#subclassName' or use a different superclass."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a subclass of `Struct` or
|
|
`Union` doesn't have any fields. Having an empty `Struct` or `Union`
|
|
isn't supported.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C`, which
|
|
extends `Struct`, doesn't declare any fields:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class [!C!] extends Struct {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the class is intended to be a struct, then declare one or more fields:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
external int x;
|
|
}
|
|
```
|
|
|
|
If the class is intended to be used as a type argument to `Pointer`, then
|
|
make it a subclass of `Opaque`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Opaque {}
|
|
```
|
|
|
|
If the class isn't intended to be a struct, then remove or change the
|
|
extends clause:
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
extraAnnotationOnStructField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Fields in a struct class must have exactly one annotation indicating the native type.
|
|
correctionMessage: Try removing the extra annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of
|
|
`Struct` has more than one annotation describing the native type of the
|
|
field.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `x` has two
|
|
annotations describing the native type of the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
[!@Int16()!]
|
|
external int x;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the annotations:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
final class C extends Struct {
|
|
@Int32()
|
|
external int x;
|
|
}
|
|
```
|
|
extraSizeAnnotationCarray:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "'Array's must have exactly one 'Array' annotation."
|
|
correctionMessage: Try removing the extra annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of
|
|
`Struct` has more than one annotation describing the size of the native
|
|
array.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `a0` has two
|
|
annotations that specify the size of the native array:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(4)
|
|
[!@Array(8)!]
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the annotations:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(8)
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
ffiNativeMustBeExternal:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Native functions must be declared external.
|
|
correctionMessage: Add the `external` keyword to the function.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function annotated as being
|
|
`@Native` isn't marked as `external`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `free` is
|
|
annotated as being `@Native`, but the function isn't marked as `external`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Pointer<Void>)>()
|
|
void [!free!](Pointer<Void> ptr) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function is a native function, then add the modifier `external`
|
|
before the return type:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Pointer<Void>)>()
|
|
external void free(Pointer<Void> ptr);
|
|
```
|
|
TODO(brianwilkerson): Fix error range
|
|
ffiNativeOnlyClassesExtendingNativefieldwrapperclass1CanBePointer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Only classes extending NativeFieldWrapperClass1 can be passed as Pointer.
|
|
correctionMessage: Pass as Handle instead.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function or method annotated
|
|
with `@Native` has a parameter in its FFI signature that is a `Pointer`,
|
|
but the corresponding Dart parameter type is a class instance that doesn't
|
|
extend `NativeFieldWrapperClass1` (or is a Pointer or TypedData).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `MyService` doesn't
|
|
extend `NativeFieldWrapperClass1`, but the `@Native` signature for its
|
|
`process` method indicates the receiver should be passed as a `Pointer<Void>`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class MyService { // MyService does not extend NativeFieldWrapperClass1
|
|
@Native<Void Function(Pointer<Void>, Int8)>(symbol: 'MyService_process')
|
|
external void [!process!](int data);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
1. **If the Dart class is intended to wrap a native object:**
|
|
Make the Dart class extend `NativeFieldWrapperClass1`. This is the
|
|
correct approach if the Dart class instance has a corresponding native
|
|
object whose pointer should be passed.
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class MyService extends NativeFieldWrapperClass1 {
|
|
@Native<Void Function(Pointer<Void>, Int8)>(symbol: 'MyService_process')
|
|
external void process(int data);
|
|
}
|
|
```
|
|
|
|
2. **If you intend to pass an opaque handle to the Dart object:**
|
|
Change the FFI signature in the `@Native` annotation to use `Handle`
|
|
instead of `Pointer` for the parameter. This allows passing a
|
|
reference to the Dart object itself, which native code can interact
|
|
with using the Dart C API.
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class MyService {
|
|
@Native<Void Function(Handle, Int8)>(symbol: 'MyService_process')
|
|
external void process(int data);
|
|
}
|
|
```
|
|
ffiNativeUnexpectedNumberOfParameters:
|
|
type: compileTimeError
|
|
parameters:
|
|
int expected: the expected number of parameters
|
|
int actual: the actual number of parameters
|
|
problemMessage: "Unexpected number of Native annotation parameters. Expected #expected but has #actual."
|
|
correctionMessage: Make sure parameters match the function annotated.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the number of parameters in the
|
|
function type used as a type argument for the `@Native` annotation doesn't
|
|
match the number of parameters in the function being annotated.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function type used
|
|
as a type argument for the `@Native` annotation (`Void Function(Double)`)
|
|
has one argument and the type of the annotated function
|
|
(`void f(double, double)`) has two arguments:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Double)>(symbol: 'f')
|
|
external void [!f!](double x, double y);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotated function is correct, then update the function type in the
|
|
`@Native` annotation to match:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Double, Double)>(symbol: 'f')
|
|
external void f(double x, double y);
|
|
```
|
|
|
|
If the function type in the `@Native` annotation is correct, then update
|
|
the annotated function to match:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Void Function(Double)>(symbol: 'f')
|
|
external void f(double x);
|
|
```
|
|
TODO(brianwilkerson): Fix error range
|
|
ffiNativeUnexpectedNumberOfParametersWithReceiver:
|
|
type: compileTimeError
|
|
parameters:
|
|
int expected: the expected number of parameters
|
|
int actual: the actual number of parameters
|
|
problemMessage: "Unexpected number of Native annotation parameters. Expected #expected but has #actual. Native instance method annotation must have receiver as first argument."
|
|
correctionMessage: Make sure parameters match the function annotated, including an extra first parameter for the receiver.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type argument used on the
|
|
`@Native` annotation of a native method doesn't include a type for the
|
|
receiver of the method.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type argument on
|
|
the `@Native` annotation (`Void Function(Double)`) doesn't include a type
|
|
for the receiver of the method:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class C {
|
|
@Native<Void Function(Double)>()
|
|
external void [!f!](double x);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an initial parameter whose type is the same as the class in which the
|
|
native method is being declared:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class C {
|
|
@Native<Void Function(C, Double)>()
|
|
external void f(double x);
|
|
}
|
|
```
|
|
ffiNativeInvalidDuplicateDefaultAsset:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "There may be at most one @DefaultAsset annotation on a library."
|
|
correctionMessage: "Try removing the extra annotation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library directive has more
|
|
than one `DefaultAsset` annotation associated with it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the library directive
|
|
has two `DefaultAsset` annotations associated with it:
|
|
|
|
```dart
|
|
@DefaultAsset('a')
|
|
@[!DefaultAsset!]('b')
|
|
library;
|
|
|
|
import 'dart:ffi';
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the `DefaultAsset` annotations:
|
|
|
|
```dart
|
|
@DefaultAsset('a')
|
|
library;
|
|
|
|
import 'dart:ffi';
|
|
```
|
|
ffiNativeInvalidMultipleAnnotations:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Native functions and fields must have exactly one `@Native` annotation."
|
|
correctionMessage: "Try removing the extra annotation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there is more than one `Native`
|
|
annotation on a single declaration.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `f` has
|
|
two `Native` annotations associated with it:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Int32 Function(Int32)>()
|
|
@[!Native!]<Int32 Function(Int32)>(isLeaf: true)
|
|
external int f(int v);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the annotations:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Native<Int32 Function(Int32)>(isLeaf: true)
|
|
external int f(int v);
|
|
```
|
|
fieldInitializerInStruct:
|
|
type: compileTimeError
|
|
parameters: none
|
|
removedIn: "3.0"
|
|
problemMessage: "Constructors in subclasses of 'Struct' and 'Union' can't have field initializers."
|
|
correctionMessage: Try removing the field initializer and marking the field as external.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor in a subclass of
|
|
either `Struct` or `Union` has one or more field initializers.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C` has a
|
|
constructor with an initializer for the field `f`:
|
|
|
|
```dart
|
|
// @dart = 2.9
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
int f;
|
|
|
|
C() : [!f = 0!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the field initializer:
|
|
|
|
```dart
|
|
// @dart = 2.9
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
int f;
|
|
|
|
C();
|
|
}
|
|
```
|
|
fieldInStructWithInitializer:
|
|
type: compileTimeError
|
|
parameters: none
|
|
removedIn: "3.0"
|
|
problemMessage: "Fields in subclasses of 'Struct' and 'Union' can't have initializers."
|
|
correctionMessage: Try removing the initializer and marking the field as external.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of
|
|
`Struct` has an initializer.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `p` has an
|
|
initializer:
|
|
|
|
```dart
|
|
// @dart = 2.9
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
Pointer [!p!] = nullptr;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the initializer:
|
|
|
|
```dart
|
|
// @dart = 2.9
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
Pointer p;
|
|
}
|
|
```
|
|
fieldMustBeExternalInStruct:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Fields of 'Struct' and 'Union' subclasses must be marked external."
|
|
correctionMessage: "Try adding the 'external' modifier."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of either
|
|
`Struct` or `Union` isn't marked as being `external`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `a` isn't
|
|
marked as being `external`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int16()
|
|
int [!a!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the required `external` modifier:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int16()
|
|
external int a;
|
|
}
|
|
```
|
|
genericStructSubclass:
|
|
type: compileTimeError
|
|
parameters:
|
|
String className: the name of the struct class
|
|
problemMessage: "The class '#className' can't extend 'Struct' or 'Union' because '#className' is generic."
|
|
correctionMessage: "Try removing the type parameters from '#className'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a subclass of either `Struct`
|
|
or `Union` has a type parameter.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `S` defines
|
|
the type parameter `T`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class [!S!]<T> extends Struct {
|
|
external Pointer notEmpty;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the type parameters from the class:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class S extends Struct {
|
|
external Pointer notEmpty;
|
|
}
|
|
```
|
|
invalidExceptionValue:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the method
|
|
problemMessage: "The method #methodName can't have an exceptional return value (the second argument) when the return type of the function is either 'void', 'Handle' or 'Pointer'."
|
|
correctionMessage: Try removing the exceptional return value.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of the method
|
|
`Pointer.fromFunction` or `NativeCallable.isolateLocal`
|
|
has a second argument (the exceptional return
|
|
value) and the type to be returned from the invocation is either `void`,
|
|
`Handle` or `Pointer`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because a second argument is
|
|
provided when the return type of `f` is `void`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef T = Void Function(Int8);
|
|
|
|
void f(int i) {}
|
|
|
|
void g() {
|
|
Pointer.fromFunction<T>(f, [!42!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the exception value:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef T = Void Function(Int8);
|
|
|
|
void f(int i) {}
|
|
|
|
void g() {
|
|
Pointer.fromFunction<T>(f);
|
|
}
|
|
```
|
|
invalidFieldTypeInStruct:
|
|
type: compileTimeError
|
|
parameters:
|
|
String type: the type of the field
|
|
problemMessage: "Fields in struct classes can't have the type '#type'. They can only be declared as 'int', 'double', 'Array', 'Pointer', or subtype of 'Struct' or 'Union'."
|
|
correctionMessage: "Try using 'int', 'double', 'Array', 'Pointer', or subtype of 'Struct' or 'Union'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of
|
|
`Struct` has a type other than `int`, `double`, `Array`, `Pointer`, or
|
|
subtype of `Struct` or `Union`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `str` has
|
|
the type `String`, which isn't one of the allowed types for fields in a
|
|
subclass of `Struct`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
external [!String!] s;
|
|
|
|
@Int32()
|
|
external int i;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use one of the allowed types for the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
final class C extends Struct {
|
|
external Pointer<Utf8> s;
|
|
|
|
@Int32()
|
|
external int i;
|
|
}
|
|
```
|
|
leafCallMustNotReturnHandle:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "FFI leaf call can't return a 'Handle'."
|
|
correctionMessage: Try changing the return type to primitive or struct.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of the `isLeaf`
|
|
argument in an invocation of either `Pointer.asFunction` or
|
|
`DynamicLibrary.lookupFunction` is `true` and the function that would be
|
|
returned would have a return type of `Handle`.
|
|
|
|
The analyzer also produces this diagnostic when the value of the `isLeaf`
|
|
argument in an `Native` annotation is `true` and the type argument on
|
|
the annotation is a function type whose return type is `Handle`.
|
|
|
|
In all of these cases, leaf calls are only supported for the types `bool`,
|
|
`int`, `float`, `double`, and, as a return type `void`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `p`
|
|
returns a `Handle`, but the `isLeaf` argument is `true`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(Pointer<NativeFunction<Handle Function()>> p) {
|
|
p.[!asFunction!]<Object Function()>(isLeaf: true);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function returns a handle, then remove the `isLeaf` argument:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(Pointer<NativeFunction<Handle Function()>> p) {
|
|
p.asFunction<Object Function()>();
|
|
}
|
|
```
|
|
|
|
If the function returns one of the supported types, then correct the type
|
|
information:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(Pointer<NativeFunction<Int32 Function()>> p) {
|
|
p.asFunction<int Function()>(isLeaf: true);
|
|
}
|
|
```
|
|
leafCallMustNotTakeHandle:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "FFI leaf call can't take arguments of type 'Handle'."
|
|
correctionMessage: Try changing the argument type to primitive or struct.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of the `isLeaf`
|
|
argument in an invocation of either `Pointer.asFunction` or
|
|
`DynamicLibrary.lookupFunction` is `true` and the function that would be
|
|
returned would have a parameter of type `Handle`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `p` has a
|
|
parameter of type `Handle`, but the `isLeaf` argument is `true`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(Pointer<NativeFunction<Void Function(Handle)>> p) {
|
|
p.[!asFunction!]<void Function(Object)>(isLeaf: true);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function has at least one parameter of type `Handle`, then remove
|
|
the `isLeaf` argument:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(Pointer<NativeFunction<Void Function(Handle)>> p) {
|
|
p.asFunction<void Function(Object)>();
|
|
}
|
|
```
|
|
|
|
If none of the function's parameters are `Handle`s, then correct the type
|
|
information:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(Pointer<NativeFunction<Void Function(Int8)>> p) {
|
|
p.asFunction<void Function(int)>(isLeaf: true);
|
|
}
|
|
```
|
|
mismatchedAnnotationOnStructField:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "The annotation doesn't match the declared type of the field."
|
|
correctionMessage: Try using a different annotation or changing the declared type to match.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the annotation on a field in a
|
|
subclass of `Struct` or `Union` doesn't match the Dart type of the field.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation
|
|
`Double` doesn't match the Dart type `int`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
[!@Double()!]
|
|
external int x;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the field is correct, then change the annotation to match:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
external int x;
|
|
}
|
|
```
|
|
|
|
If the annotation is correct, then change the type of the field to match:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Double()
|
|
external double x;
|
|
}
|
|
```
|
|
missingAnnotationOnStructField:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type that is missing a native type annotation
|
|
String superclassName: the superclass which is extended by this field's class
|
|
problemMessage: "Fields of type '#type' in a subclass of '#superclassName' must have an annotation indicating the native type."
|
|
correctionMessage: Try adding an annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of
|
|
`Struct` or `Union` whose type requires an annotation doesn't have one.
|
|
The Dart types `int`, `double`, and `Array` are used to represent multiple
|
|
C types, and the annotation specifies which of the compatible C types the
|
|
field represents.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `x` doesn't
|
|
have an annotation indicating the underlying width of the integer value:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
external [!int!] x;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an appropriate annotation to the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int64()
|
|
external int x;
|
|
}
|
|
```
|
|
missingExceptionValue:
|
|
type: compileTimeError
|
|
parameters:
|
|
String methodName: the name of the method
|
|
problemMessage: "The method #methodName must have an exceptional return value (the second argument) when the return type of the function is neither 'void', 'Handle', nor 'Pointer'."
|
|
correctionMessage: Try adding an exceptional return value.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of the method
|
|
`Pointer.fromFunction` or `NativeCallable.isolateLocal`
|
|
doesn't have a second argument (the exceptional
|
|
return value) when the type to be returned from the invocation is neither
|
|
`void`, `Handle`, nor `Pointer`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type returned by
|
|
`f` is expected to be an 8-bit integer but the call to `fromFunction`
|
|
doesn't include an exceptional return argument:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int f(int i) => i * 2;
|
|
|
|
void g() {
|
|
Pointer.[!fromFunction!]<Int8 Function(Int8)>(f);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an exceptional return type:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int f(int i) => i * 2;
|
|
|
|
void g() {
|
|
Pointer.fromFunction<Int8 Function(Int8)>(f, 0);
|
|
}
|
|
```
|
|
missingFieldTypeInStruct:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Fields in struct classes must have an explicitly declared type of 'int', 'double' or 'Pointer'."
|
|
correctionMessage: "Try using 'int', 'double' or 'Pointer'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of
|
|
`Struct` or `Union` doesn't have a type annotation. Every field must have
|
|
an explicit type, and the type must either be `int`, `double`, `Pointer`,
|
|
or a subclass of either `Struct` or `Union`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `str`
|
|
doesn't have a type annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
external var [!str!];
|
|
|
|
@Int32()
|
|
external int i;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Explicitly specify the type of the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
final class C extends Struct {
|
|
external Pointer<Utf8> str;
|
|
|
|
@Int32()
|
|
external int i;
|
|
}
|
|
```
|
|
missingSizeAnnotationCarray:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Fields of type 'Array' must have exactly one 'Array' annotation."
|
|
correctionMessage: "Try adding an 'Array' annotation, or removing all but one of the annotations."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a field in a subclass of either
|
|
`Struct` or `Union` has a type of `Array` but doesn't have a single
|
|
`Array` annotation indicating the dimensions of the array.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `a0` doesn't
|
|
have an `Array` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
external [!Array<Uint8>!] a0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Ensure that there's exactly one `Array` annotation on the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(8)
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
mustBeANativeFunctionType:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type that should be a valid dart:ffi native type.
|
|
String functionName: the name of the function whose invocation depends on this relationship
|
|
problemMessage: "The type '#type' given to '#functionName' must be a valid 'dart:ffi' native function type."
|
|
correctionMessage: "Try changing the type to only use members for 'dart:ffi'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of either
|
|
`Pointer.fromFunction`, `DynamicLibrary.lookupFunction`,
|
|
or a `NativeCallable` constructor, has a type
|
|
argument(whether explicit or inferred) that isn't a native function type.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type `T` can be
|
|
any subclass of `Function` but the type argument for `fromFunction` is
|
|
required to be a native function type:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int f(int i) => i * 2;
|
|
|
|
class C<T extends Function> {
|
|
void g() {
|
|
Pointer.fromFunction<[!T!]>(f, 0);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use a native function type as the type argument to the invocation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int f(int i) => i * 2;
|
|
|
|
class C<T extends Function> {
|
|
void g() {
|
|
Pointer.fromFunction<Int32 Function(Int32)>(f, 0);
|
|
}
|
|
}
|
|
```
|
|
mustBeASubtype:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type subtype: the type that should be a subtype
|
|
Type supertype: the supertype that the subtype is compared to
|
|
String name: the name of the function whose invocation depends on this relationship
|
|
problemMessage: "The type '#subtype' must be a subtype of '#supertype' for '#name'."
|
|
correctionMessage: Try changing one or both of the type arguments.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic in two cases:
|
|
- In an invocation of `Pointer.fromFunction`, or a
|
|
`NativeCallable` constructor where the type argument
|
|
(whether explicit or inferred) isn't a supertype of the type of the
|
|
function passed as the first argument to the method.
|
|
- In an invocation of `DynamicLibrary.lookupFunction` where the first type
|
|
argument isn't a supertype of the second type argument.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of the
|
|
function `f` (`String Function(int)`) isn't a subtype of the type
|
|
argument `T` (`Int8 Function(Int8)`):
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef T = Int8 Function(Int8);
|
|
|
|
double f(double i) => i;
|
|
|
|
void g() {
|
|
Pointer.fromFunction<T>([!f!], 5.0);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function is correct, then change the type argument to match:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef T = Float Function(Float);
|
|
|
|
double f(double i) => i;
|
|
|
|
void g() {
|
|
Pointer.fromFunction<T>(f, 5.0);
|
|
}
|
|
```
|
|
|
|
If the type argument is correct, then change the function to match:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef T = Int8 Function(Int8);
|
|
|
|
int f(int i) => i;
|
|
|
|
void g() {
|
|
Pointer.fromFunction<T>(f, 5);
|
|
}
|
|
```
|
|
mustReturnVoid:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the return type that should be 'void'.
|
|
problemMessage: "The return type of the function passed to 'NativeCallable.listener' must be 'void' rather than '#type'."
|
|
correctionMessage: "Try changing the return type to 'void'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when you pass a function
|
|
that doesn't return `void` to the `NativeCallable.listener` constructor.
|
|
|
|
`NativeCallable.listener` creates a native callable that can be invoked
|
|
from any thread. The native code that invokes the callable sends a message
|
|
back to the isolate that created the callable, and doesn't wait for a
|
|
response. So it isn't possible to return a result from the callable.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function
|
|
`f` returns `int` rather than `void`.
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
int f(int i) => i * 2;
|
|
|
|
void g() {
|
|
NativeCallable<Int32 Function(Int32)>.listener([!f!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the return type of the function to `void`.
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
void f(int i) => print(i * 2);
|
|
|
|
void g() {
|
|
NativeCallable<Void Function(Int32)>.listener(f);
|
|
}
|
|
```
|
|
negativeVariableDimension:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: The variable dimension of a variable-length array must be non-negative.
|
|
correctionMessage: Try using a value that is zero or greater.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic in two cases.
|
|
|
|
The first is when the variable dimension given in an
|
|
`Array.variableWithVariableDimension` annotation is negative. The variable
|
|
dimension is the first argument in the annotation.
|
|
|
|
The second is when the variable dimension given in an
|
|
`Array.variableMulti` annotation is negative. The variable dimension is
|
|
specified in the `variableDimension` argument of the annotation.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because a variable dimension
|
|
of `-1` was provided in the `Array.variableWithVariableDimension`
|
|
annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct extends Struct {
|
|
@Array.variableWithVariableDimension([!-1!])
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because a variable dimension
|
|
of `-1` was provided in the `Array.variableMulti` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct2 extends Struct {
|
|
@Array.variableMulti(variableDimension: [!-1!], [1, 2])
|
|
external Array<Array<Array<Uint8>>> a0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the variable dimension with zero (`0`) or a positive number:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct extends Struct {
|
|
@Array.variableWithVariableDimension(1)
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
|
|
Change the variable dimension with zero (`0`) or a positive number:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct2 extends Struct {
|
|
@Array.variableMulti(variableDimension: 1, [1, 2])
|
|
external Array<Array<Array<Uint8>>> a0;
|
|
}
|
|
```
|
|
nonConstantTypeArgument:
|
|
type: compileTimeError
|
|
parameters:
|
|
String executableName: the name of the function, method, or constructor having type arguments
|
|
problemMessage: "The type arguments to '#executableName' must be known at compile time, so they can't be type parameters."
|
|
correctionMessage: Try changing the type argument to be a constant type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type arguments to a method
|
|
are required to be known at compile time, but a type parameter, whose
|
|
value can't be known at compile time, is used as a type argument.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type argument to
|
|
`Pointer.asFunction` must be known at compile time, but the type parameter
|
|
`R`, which isn't known at compile time, is being used as the type
|
|
argument:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef T = int Function(int);
|
|
|
|
class C<R extends T> {
|
|
void m(Pointer<NativeFunction<T>> p) {
|
|
p.asFunction<[!R!]>();
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove any uses of type parameters:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
class C {
|
|
void m(Pointer<NativeFunction<Int64 Function(Int64)>> p) {
|
|
p.asFunction<int Function(int)>();
|
|
}
|
|
}
|
|
```
|
|
nonNativeFunctionTypeArgumentToPointer:
|
|
type: compileTimeError
|
|
parameters:
|
|
Type type: the type that should be a valid dart:ffi native type.
|
|
problemMessage: "Can't invoke 'asFunction' because the function signature '#type' for the pointer isn't a valid C function signature."
|
|
correctionMessage: "Try changing the function argument in 'NativeFunction' to only use NativeTypes."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the method `asFunction` is
|
|
invoked on a pointer to a native function, but the signature of the native
|
|
function isn't a valid C function signature.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because function signature
|
|
associated with the pointer `p` (`FNative`) isn't a valid C function
|
|
signature:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef FNative = int Function(int);
|
|
typedef F = int Function(int);
|
|
|
|
class C {
|
|
void f(Pointer<NativeFunction<FNative>> p) {
|
|
p.asFunction<[!F!]>();
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Make the `NativeFunction` signature a valid C signature:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
typedef FNative = Int8 Function(Int8);
|
|
typedef F = int Function(int);
|
|
|
|
class C {
|
|
void f(Pointer<NativeFunction<FNative>> p) {
|
|
p.asFunction<F>();
|
|
}
|
|
}
|
|
```
|
|
nonPositiveArrayDimension:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Array dimensions must be positive numbers.
|
|
correctionMessage: Try changing the input to a positive number.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a dimension given in an `Array`
|
|
annotation is less than or equal to zero (`0`).
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because an array dimension of
|
|
`-8` was provided:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct extends Struct {
|
|
@Array([!-8!])
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the dimension to be a positive integer:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct extends Struct {
|
|
@Array(8)
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
|
|
If this is a variable length inline array, change the annotation to
|
|
`Array.variable()`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class MyStruct extends Struct {
|
|
@Array.variable()
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
nonSizedTypeArgument:
|
|
type: compileTimeError
|
|
parameters:
|
|
String fieldName: the name of the field
|
|
Type type: the type of the field
|
|
problemMessage: "The type '#type' isn't a valid type argument for '#fieldName'. The type argument must be a native integer, 'Float', 'Double', 'Pointer', or subtype of 'Struct', 'Union', or 'AbiSpecificInteger'."
|
|
correctionMessage: "Try using a native integer, 'Float', 'Double', 'Pointer', or subtype of 'Struct', 'Union', or 'AbiSpecificInteger'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type argument for the class
|
|
`Array` isn't one of the valid types: either a native integer, `Float`,
|
|
`Double`, `Pointer`, or subtype of `Struct`, `Union`, or
|
|
`AbiSpecificInteger`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type argument to
|
|
`Array` is `Void`, and `Void` isn't one of the valid types:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(8)
|
|
external Array<[!Void!]> a0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the type argument to one of the valid types:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(8)
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
packedAnnotation:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Structs must have at most one 'Packed' annotation."
|
|
correctionMessage: "Try removing extra 'Packed' annotations."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a subclass of `Struct` has more
|
|
than one `Packed` annotation.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C`, which
|
|
is a subclass of `Struct`, has two `Packed` annotations:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Packed(1)
|
|
[!@Packed(1)!]
|
|
final class C extends Struct {
|
|
external Pointer<Uint8> notEmpty;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove all but one of the annotations:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Packed(1)
|
|
final class C extends Struct {
|
|
external Pointer<Uint8> notEmpty;
|
|
}
|
|
```
|
|
packedAnnotationAlignment:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: Only packing to 1, 2, 4, 8, and 16 bytes is supported.
|
|
correctionMessage: "Try changing the 'Packed' annotation alignment to 1, 2, 4, 8, or 16."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the argument to the `Packed`
|
|
annotation isn't one of the allowed values: 1, 2, 4, 8, or 16.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the argument to the
|
|
`Packed` annotation (`3`) isn't one of the allowed values:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Packed([!3!])
|
|
final class C extends Struct {
|
|
external Pointer<Uint8> notEmpty;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the alignment to be one of the allowed values:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
@Packed(4)
|
|
final class C extends Struct {
|
|
external Pointer<Uint8> notEmpty;
|
|
}
|
|
```
|
|
variableLengthArrayNotLast:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "Variable length 'Array's must only occur as the last field of Structs."
|
|
correctionMessage: "Try adjusting the arguments in the 'Array' annotation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a variable length inline `Array`
|
|
is not the last member of a `Struct`.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `a0` has a
|
|
type with three nested arrays, but only two dimensions are given in the
|
|
`Array` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
[!@Array.variable()!]
|
|
external Array<Uint8> a0;
|
|
|
|
@Uint8()
|
|
external int a1;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Move the variable length inline `Array` to be the last field in the struct.
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Uint8()
|
|
external int a1;
|
|
|
|
@Array.variable()
|
|
external Array<Uint8> a0;
|
|
}
|
|
```
|
|
|
|
If the inline array has a fixed size, annotate it with the size:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(10)
|
|
external Array<Uint8> a0;
|
|
|
|
@Uint8()
|
|
external int a1;
|
|
}
|
|
```
|
|
sizeAnnotationDimensions:
|
|
type: compileTimeError
|
|
parameters: none
|
|
problemMessage: "'Array's must have an 'Array' annotation that matches the dimensions."
|
|
correctionMessage: "Try adjusting the arguments in the 'Array' annotation."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the number of dimensions
|
|
specified in an `Array` annotation doesn't match the number of nested
|
|
arrays specified by the type of a field.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `a0` has a
|
|
type with three nested arrays, but only two dimensions are given in the
|
|
`Array` annotation:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
[!@Array(8, 8)!]
|
|
external Array<Array<Array<Uint8>>> a0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the field is correct, then fix the annotation to have the
|
|
required number of dimensions:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(8, 8, 4)
|
|
external Array<Array<Array<Uint8>>> a0;
|
|
}
|
|
```
|
|
|
|
If the type of the field is wrong, then fix the type of the field:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Array(8, 8)
|
|
external Array<Array<Uint8>> a0;
|
|
}
|
|
```
|
|
subtypeOfFfiClassInExtends:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the class being extended, implemented, or mixed in
|
|
removedIn: "3.0"
|
|
sharedName: subtypeOfFfiClass
|
|
problemMessage: "The class '#subclassName' can't extend '#superclassName'."
|
|
correctionMessage: "Try extending 'Struct' or 'Union'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class extends any FFI class
|
|
other than `Struct` or `Union`, or implements or mixes in any FFI class.
|
|
`Struct` and `Union` are the only FFI classes that can be subtyped, and
|
|
then only by extending them.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C` extends
|
|
`Double`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends [!Double!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the class should extend either `Struct` or `Union`, then change the
|
|
declaration of the class:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class C extends Struct {
|
|
@Int32()
|
|
external int i;
|
|
}
|
|
```
|
|
|
|
If the class shouldn't extend either `Struct` or `Union`, then remove any
|
|
references to FFI classes:
|
|
|
|
```dart
|
|
final class C {}
|
|
```
|
|
subtypeOfFfiClassInImplements:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the class being extended, implemented, or mixed in
|
|
removedIn: "3.0"
|
|
sharedName: subtypeOfFfiClass
|
|
problemMessage: "The class '#subclassName' can't implement '#superclassName'."
|
|
correctionMessage: "Try implementing 'Allocator' or 'Finalizable'."
|
|
hasPublishedDocs: true
|
|
subtypeOfFfiClassInWith:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the class being extended, implemented, or mixed in
|
|
removedIn: "3.0"
|
|
sharedName: subtypeOfFfiClass
|
|
problemMessage: "The class '#subclassName' can't mix in '#superclassName'."
|
|
correctionMessage: "Try extending 'Struct' or 'Union'."
|
|
hasPublishedDocs: true
|
|
subtypeOfStructClassInExtends:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the class being extended, implemented, or mixed in
|
|
sharedName: subtypeOfStructClass
|
|
problemMessage: "The class '#subclassName' can't extend '#superclassName' because '#superclassName' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'."
|
|
correctionMessage: "Try extending 'Struct', 'Union', or 'AbiSpecificInteger' directly."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class extends, implements, or
|
|
mixes in a class that extends either `Struct` or `Union`. Classes can only
|
|
extend either `Struct` or `Union` directly.
|
|
|
|
For more information about FFI, see [C interop using dart:ffi][ffi].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `C` extends
|
|
`S`, and `S` extends `Struct`:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class S extends Struct {
|
|
external Pointer f;
|
|
}
|
|
|
|
final class C extends [!S!] {
|
|
external Pointer g;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're trying to define a struct or union that shares some fields
|
|
declared by a different struct or union, then extend `Struct` or `Union`
|
|
directly and copy the shared fields:
|
|
|
|
```dart
|
|
import 'dart:ffi';
|
|
|
|
final class S extends Struct {
|
|
external Pointer f;
|
|
}
|
|
|
|
final class C extends Struct {
|
|
external Pointer f;
|
|
|
|
external Pointer g;
|
|
}
|
|
```
|
|
subtypeOfStructClassInImplements:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the class being extended, implemented, or mixed in
|
|
sharedName: subtypeOfStructClass
|
|
problemMessage: "The class '#subclassName' can't implement '#superclassName' because '#superclassName' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'."
|
|
correctionMessage: "Try extending 'Struct', 'Union', or 'AbiSpecificInteger' directly."
|
|
hasPublishedDocs: true
|
|
subtypeOfStructClassInWith:
|
|
type: compileTimeError
|
|
parameters:
|
|
String subclassName: the name of the subclass
|
|
String superclassName: the name of the class being extended, implemented, or mixed in
|
|
sharedName: subtypeOfStructClass
|
|
problemMessage: "The class '#subclassName' can't mix in '#superclassName' because '#superclassName' is a subtype of 'Struct', 'Union', or 'AbiSpecificInteger'."
|
|
correctionMessage: "Try extending 'Struct', 'Union', or 'AbiSpecificInteger' directly."
|
|
hasPublishedDocs: true
|
|
HintCode:
|
|
deprecatedColonForDefaultValue:
|
|
type: hint
|
|
parameters: none
|
|
problemMessage: Using a colon as the separator before a default value is deprecated and will not be supported in language version 3.0 and later.
|
|
correctionMessage: Try replacing the colon with an equal sign.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Note: Since this diagnostic is only produced in pre-3.0 code, we do not
|
|
plan to go through the exercise of converting it to a Warning.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a colon (`:`) is used as the
|
|
separator before the default value of an optional named parameter.
|
|
While this syntax is allowed, it is deprecated in favor of
|
|
using an equal sign (`=`).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because a colon is being used
|
|
before the default value of the optional parameter `i`:
|
|
|
|
```dart
|
|
void f({int i [!:!] 0}) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the colon with an equal sign.
|
|
|
|
```dart
|
|
void f({int i = 0}) {}
|
|
```
|
|
deprecatedMemberUse:
|
|
type: hint
|
|
parameters:
|
|
String name: the name of the member
|
|
problemMessage: "'#name' is deprecated and shouldn't be used."
|
|
correctionMessage: Try replacing the use of the deprecated member with the replacement.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a deprecated library or class
|
|
member is used in a different package.
|
|
|
|
#### Example
|
|
|
|
If the method `m` in the class `C` is annotated with `@deprecated`, then
|
|
the following code produces this diagnostic:
|
|
|
|
```dart
|
|
void f(C c) {
|
|
c.[!m!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
The documentation for declarations that are annotated with `@deprecated`
|
|
should indicate what code to use in place of the deprecated code.
|
|
deprecatedMemberUseWithMessage:
|
|
type: hint
|
|
parameters:
|
|
String name: the name of the member
|
|
String details: message details
|
|
sharedName: deprecatedMemberUse
|
|
problemMessage: "'#name' is deprecated and shouldn't be used. #details"
|
|
correctionMessage: Try replacing the use of the deprecated member with the replacement.
|
|
hasPublishedDocs: true
|
|
divisionOptimization:
|
|
type: hint
|
|
parameters: none
|
|
removedIn: "3.5"
|
|
problemMessage: The operator x ~/ y is more efficient than (x / y).toInt().
|
|
correctionMessage: "Try re-writing the expression to use the '~/' operator."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the result of dividing two
|
|
numbers is converted to an integer using `toInt`. Dart has a built-in
|
|
integer division operator that is both more efficient and more concise.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the result of dividing
|
|
`x` and `y` is converted to an integer using `toInt`:
|
|
|
|
```dart
|
|
int divide(int x, int y) => [!(x / y).toInt()!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use the integer division operator (`~/`):
|
|
|
|
```dart
|
|
int divide(int x, int y) => x ~/ y;
|
|
```
|
|
importDeferredLibraryWithLoadFunction:
|
|
type: hint
|
|
parameters: none
|
|
problemMessage: "The imported library defines a top-level function named 'loadLibrary' that is hidden by deferring this library."
|
|
correctionMessage: Try changing the import to not be deferred, or rename the function in the imported library.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library that declares a
|
|
function named `loadLibrary` is imported using a deferred import. A
|
|
deferred import introduces an implicit function named `loadLibrary`. This
|
|
function is used to load the contents of the deferred library, and the
|
|
implicit function hides the explicit declaration in the deferred library.
|
|
|
|
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 function named `loadLibrary`:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
void loadLibrary(Library library) {}
|
|
|
|
class Library {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the implicit
|
|
declaration of `a.loadLibrary` is hiding the explicit declaration of
|
|
`loadLibrary` in `a.dart`:
|
|
|
|
```dart
|
|
[!import 'a.dart' deferred as a;!]
|
|
|
|
void f() {
|
|
a.Library();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the imported library isn't required to be deferred, then remove the
|
|
keyword `deferred`:
|
|
|
|
```dart
|
|
import 'a.dart' as a;
|
|
|
|
void f() {
|
|
a.Library();
|
|
}
|
|
```
|
|
|
|
If the imported library is required to be deferred and you need to
|
|
reference the imported function, then rename the function in the imported
|
|
library:
|
|
|
|
```dart
|
|
void populateLibrary(Library library) {}
|
|
|
|
class Library {}
|
|
```
|
|
|
|
If the imported library is required to be deferred and you don't need to
|
|
reference the imported function, then add a `hide` clause:
|
|
|
|
```dart
|
|
import 'a.dart' deferred as a hide loadLibrary;
|
|
|
|
void f() {
|
|
a.Library();
|
|
}
|
|
```
|
|
importOfLegacyLibraryIntoNullSafe:
|
|
type: hint
|
|
parameters:
|
|
String p0: the name of the library
|
|
removedIn: "3.0"
|
|
problemMessage: "The library '#p0' is legacy, and shouldn't be imported into a null safe library."
|
|
correctionMessage: Try migrating the imported library.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
https://github.com/dart-lang/sdk/issues/44063
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a library that is null safe
|
|
imports a library that isn't null safe.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
// @dart = 2.9
|
|
|
|
class A {}
|
|
```
|
|
|
|
The following code produces this diagnostic because a library that null
|
|
safe is importing a library that isn't null safe:
|
|
|
|
```dart
|
|
import [!'a.dart'!];
|
|
|
|
A? f() => null;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can migrate the imported library to be null safe, then migrate it
|
|
and update or remove the migrated library's language version.
|
|
|
|
If you can't migrate the imported library, then the importing library
|
|
needs to have a language version that is before 2.12, when null safety was
|
|
enabled by default.
|
|
unnecessaryImport:
|
|
type: hint
|
|
parameters:
|
|
String unnecessaryUri: the URI that is not necessary
|
|
String reasonUri: the URI that makes it unnecessary
|
|
problemMessage: "The import of '#unnecessaryUri' is unnecessary because all of the used elements are also provided by the import of '#reasonUri'."
|
|
correctionMessage: Try removing the import directive.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import isn't needed because
|
|
all of the names that are imported and referenced within the importing
|
|
library are also visible through another import.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
class A {}
|
|
```
|
|
|
|
And, given a file `b.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/b.dart"
|
|
export 'a.dart';
|
|
|
|
class B {}
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `A`, which is
|
|
imported from `a.dart`, is also imported from `b.dart`. Removing the import
|
|
of `a.dart` leaves the semantics unchanged:
|
|
|
|
```dart
|
|
import [!'a.dart'!];
|
|
import 'b.dart';
|
|
|
|
void f(A a, B b) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the import isn't needed, then remove it.
|
|
|
|
If some of the names imported by this import are intended to be used but
|
|
aren't yet, and if those names aren't imported by other imports, then add
|
|
the missing references to those names.
|
|
ManifestWarningCode:
|
|
cameraPermissionsIncompatible:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Camera permissions make app incompatible for Chrome OS, consider adding optional features "android.hardware.camera" and "android.hardware.camera.autofocus".
|
|
correctionMessage: 'Try adding `<uses-feature android:name="android.hardware.camera" android:required="false">` `<uses-feature android:name="android.hardware.camera.autofocus" android:required="false">`.'
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A code indicating that the camera permissions is not supported on Chrome
|
|
OS.
|
|
nonResizableActivity:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: The `<activity>` element should be allowed to be resized to allow users to take advantage of the multi-window environment on Chrome OS
|
|
correctionMessage: Consider declaring the corresponding activity element with `resizableActivity="true"` attribute.
|
|
hasPublishedDocs: false
|
|
comment: A code indicating that the activity is set to be non resizable.
|
|
noTouchscreenFeature:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: 'The default "android.hardware.touchscreen" needs to be optional for Chrome OS. '
|
|
correctionMessage: 'Consider adding <uses-feature android:name="android.hardware.touchscreen" android:required="false" /> to the manifest.'
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A code indicating that the touchscreen feature is not specified in the
|
|
manifest.
|
|
permissionImpliesUnsupportedHardware:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the feature tag
|
|
problemMessage: "Permission makes app incompatible for Chrome OS, consider adding optional #name feature tag, "
|
|
correctionMessage: ' Try adding `<uses-feature android:name="#name" android:required="false">`.'
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A code indicating that a specified permission is not supported on Chrome
|
|
OS.
|
|
settingOrientationOnActivity:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: The `<activity>` element should not be locked to any orientation so that users can take advantage of the multi-window environments and larger screens on Chrome OS
|
|
correctionMessage: Consider declaring the corresponding activity element with `screenOrientation="unspecified"` or `"fullSensor"` attribute.
|
|
hasPublishedDocs: false
|
|
comment: A code indicating that the activity is locked to an orientation.
|
|
unsupportedChromeOsFeature:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the feature
|
|
problemMessage: "The feature #name isn't supported on Chrome OS, consider making it optional."
|
|
correctionMessage: 'Try changing to `android:required="false"` for this feature.'
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A code indicating that a specified feature is not supported on Chrome OS.
|
|
unsupportedChromeOsHardware:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the feature
|
|
problemMessage: "The feature #name isn't supported on Chrome OS, consider making it optional."
|
|
correctionMessage: 'Try adding `android:required="false"` for this feature.'
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A code indicating that a specified hardware feature is not supported on
|
|
Chrome OS.
|
|
ParserErrorCode:
|
|
abstractStaticMethod:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Static methods can't be declared to be 'abstract'."
|
|
correctionMessage: "Try removing the keyword 'abstract'."
|
|
hasPublishedDocs: false
|
|
asyncKeywordUsedAsIdentifier:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The keywords 'await' and 'yield' can't be used as identifiers in an asynchronous or generator function."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
16.32 Identifier Reference: It is a compile-time error if any of the
|
|
identifiers async, await, or yield is used as an identifier in a function
|
|
body marked with either async, async, or sync.
|
|
constConstructorWithBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Const constructors can't have a body."
|
|
correctionMessage: "Try removing either the 'const' keyword or the body."
|
|
hasPublishedDocs: false
|
|
constPrimaryConstructorWithBlockBody:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: constPrimaryConstructorWithBody
|
|
problemMessage: "The body part of a constant primary constructor can't have a block body."
|
|
correctionMessage: "Try replacing the block body with a semicolon, or removing the 'const' modifier."
|
|
hasPublishedDocs: false
|
|
constPrimaryConstructorWithExpressionBody:
|
|
type: compileTimeError
|
|
parameters: none
|
|
sharedName: constPrimaryConstructorWithBody
|
|
problemMessage: "The body part of a constant primary constructor can't have an expression body."
|
|
correctionMessage: "Try replacing the expression body with a semicolon, or removing the 'const' modifier."
|
|
hasPublishedDocs: false
|
|
covariantConstructor:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A constructor can't be declared to be 'covariant'."
|
|
correctionMessage: "Try removing the keyword 'covariant'."
|
|
hasPublishedDocs: false
|
|
defaultValueInFunctionType:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Parameters in a function type can't have default values."
|
|
correctionMessage: Try removing the default value.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function type associated with
|
|
a parameter includes optional parameters that have a default value. This
|
|
isn't allowed because the default values of parameters aren't part of the
|
|
function's type, and therefore including them doesn't provide any value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the parameter `p` has a
|
|
default value even though it's part of the type of the parameter `g`:
|
|
|
|
```dart
|
|
void f(void Function([int p [!=!] 0]) g) {
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the default value from the function-type's parameter:
|
|
|
|
```dart
|
|
void f(void Function([int p]) g) {
|
|
}
|
|
```
|
|
emptyEnumBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: An enum must declare at least one constant name.
|
|
correctionMessage: Try declaring a constant.
|
|
hasPublishedDocs: false
|
|
expectedCaseOrDefault:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Expected 'case' or 'default'."
|
|
correctionMessage: Try placing this code inside a case clause.
|
|
hasPublishedDocs: false
|
|
expectedClassMember:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a class member.
|
|
correctionMessage: Try placing this code inside a class member.
|
|
hasPublishedDocs: false
|
|
expectedExecutable:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a method, getter, setter or operator declaration.
|
|
correctionMessage: This appears to be incomplete code. Try removing it or completing it.
|
|
hasPublishedDocs: false
|
|
expectedListOrMapLiteral:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a list or map literal.
|
|
correctionMessage: Try inserting a list or map literal, or remove the type arguments.
|
|
hasPublishedDocs: false
|
|
expectedNamedTypeExtends:
|
|
type: syntacticError
|
|
parameters: none
|
|
sharedName: expectedNamedType
|
|
problemMessage: Expected a class name.
|
|
correctionMessage: Try using a class name, possibly with type arguments.
|
|
hasPublishedDocs: false
|
|
expectedNamedTypeImplements:
|
|
type: syntacticError
|
|
parameters: none
|
|
sharedName: expectedNamedType
|
|
problemMessage: Expected the name of a class or mixin.
|
|
correctionMessage: Try using a class or mixin name, possibly with type arguments.
|
|
hasPublishedDocs: false
|
|
expectedNamedTypeOn:
|
|
type: syntacticError
|
|
parameters: none
|
|
sharedName: expectedNamedType
|
|
problemMessage: Expected the name of a class or mixin.
|
|
correctionMessage: Try using a class or mixin name, possibly with type arguments.
|
|
hasPublishedDocs: false
|
|
expectedNamedTypeWith:
|
|
type: syntacticError
|
|
parameters: none
|
|
sharedName: expectedNamedType
|
|
problemMessage: Expected a mixin name.
|
|
correctionMessage: Try using a mixin name, possibly with type arguments.
|
|
hasPublishedDocs: false
|
|
expectedRepresentationField:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a representation field.
|
|
correctionMessage: Try providing the representation field for this extension type.
|
|
hasPublishedDocs: false
|
|
expectedRepresentationType:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a representation type.
|
|
correctionMessage: Try providing the representation type for this extension type.
|
|
hasPublishedDocs: false
|
|
expectedStringLiteral:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a string literal.
|
|
hasPublishedDocs: false
|
|
expectedToken:
|
|
type: syntacticError
|
|
parameters:
|
|
String token: the token that was expected but not found
|
|
problemMessage: "Expected to find '#token'."
|
|
hasPublishedDocs: false
|
|
expectedTypeName:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected a type name.
|
|
hasPublishedDocs: false
|
|
externalGetterWithBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "External getters can't have a body."
|
|
correctionMessage: "Try removing the body of the getter, or removing the keyword 'external'."
|
|
hasPublishedDocs: false
|
|
externalOperatorWithBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "External operators can't have a body."
|
|
correctionMessage: "Try removing the body of the operator, or removing the keyword 'external'."
|
|
hasPublishedDocs: false
|
|
externalSetterWithBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "External setters can't have a body."
|
|
correctionMessage: "Try removing the body of the setter, or removing the keyword 'external'."
|
|
hasPublishedDocs: false
|
|
factoryWithoutBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A non-redirecting 'factory' constructor must have a body."
|
|
correctionMessage: Try adding a body to the constructor.
|
|
hasPublishedDocs: false
|
|
factoryWithInitializers:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A 'factory' constructor can't have initializers."
|
|
correctionMessage: "Try removing the 'factory' keyword to make this a generative constructor, or removing the initializers."
|
|
hasPublishedDocs: false
|
|
finalConstructor:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A constructor can't be declared to be 'final'."
|
|
correctionMessage: "Try removing the keyword 'final'."
|
|
hasPublishedDocs: false
|
|
finalMethod:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Getters, setters and methods can't be declared to be 'final'."
|
|
correctionMessage: "Try removing the keyword 'final'."
|
|
hasPublishedDocs: false
|
|
getterInFunction:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Getters can't be defined within methods or functions."
|
|
correctionMessage: Try moving the getter outside the method or function, or converting the getter to a function.
|
|
hasPublishedDocs: false
|
|
getterWithParameters:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Getters must be declared without a parameter list.
|
|
correctionMessage: "Try removing the parameter list, or removing the keyword 'get' to define a method rather than a getter."
|
|
hasPublishedDocs: false
|
|
invalidCodePoint:
|
|
type: syntacticError
|
|
parameters:
|
|
String escapeSequence: the invalid escape sequence
|
|
problemMessage: "The escape sequence '#escapeSequence' isn't a valid code point."
|
|
hasPublishedDocs: false
|
|
invalidCommentReference:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Comment references should contain a possibly prefixed identifier and can start with 'new', but shouldn't contain anything else."
|
|
hasPublishedDocs: false
|
|
invalidGenericFunctionType:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Invalid generic function type.
|
|
correctionMessage: "Try using a generic function type (returnType 'Function(' parameters ')')."
|
|
hasPublishedDocs: false
|
|
invalidLiteralInConfiguration:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The literal in a configuration can't contain interpolation."
|
|
correctionMessage: Try removing the interpolation expressions.
|
|
hasPublishedDocs: false
|
|
invalidOperatorForSuper:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the operator being applied to 'super'
|
|
removedIn: "3.10"
|
|
problemMessage: "The operator '#p0' can't be used with 'super'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
Only generated by the old parser.
|
|
Replaced by INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER.
|
|
invalidStarAfterAsync:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The modifier 'async*' isn't allowed for an expression function body."
|
|
correctionMessage: Try converting the body to a block.
|
|
hasPublishedDocs: false
|
|
invalidSync:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The modifier 'sync' isn't allowed for an expression function body."
|
|
correctionMessage: Try converting the body to a block.
|
|
hasPublishedDocs: false
|
|
invalidUseOfIdentifierAugmented:
|
|
type: syntacticError
|
|
parameters: none
|
|
experiment: augmentations
|
|
problemMessage: The identifier 'augmented' can only be used to reference the augmented declaration inside an augmentation.
|
|
correctionMessage: Try using a different identifier.
|
|
hasPublishedDocs: false
|
|
localFunctionDeclarationModifier:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Local function declarations can't specify any modifiers."
|
|
correctionMessage: Try removing the modifier.
|
|
hasPublishedDocs: false
|
|
missingClosingParenthesis:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: The closing parenthesis is missing.
|
|
correctionMessage: Try adding the closing parenthesis.
|
|
hasPublishedDocs: false
|
|
missingEnumBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: An enum definition must have a body with at least one constant name.
|
|
correctionMessage: Try adding a body and defining at least one constant.
|
|
hasPublishedDocs: false
|
|
missingExpressionInInitializer:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected an expression after the assignment operator.
|
|
correctionMessage: Try adding the value to be assigned, or remove the assignment operator.
|
|
hasPublishedDocs: false
|
|
missingFunctionBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: A function body must be provided.
|
|
correctionMessage: Try adding a function body.
|
|
hasPublishedDocs: false
|
|
missingFunctionKeyword:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Function types must have the keyword 'Function' before the parameter list."
|
|
correctionMessage: "Try adding the keyword 'Function'."
|
|
hasPublishedDocs: false
|
|
missingFunctionParameters:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Functions must have an explicit list of parameters.
|
|
correctionMessage: Try adding a parameter list.
|
|
hasPublishedDocs: false
|
|
missingGet:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Getters must have the keyword 'get' before the getter name."
|
|
correctionMessage: "Try adding the keyword 'get'."
|
|
hasPublishedDocs: false
|
|
missingIdentifier:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected an identifier.
|
|
hasPublishedDocs: false
|
|
missingMethodParameters:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Methods must have an explicit list of parameters.
|
|
correctionMessage: Try adding a parameter list.
|
|
hasPublishedDocs: false
|
|
missingNameForNamedParameter:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Named parameters in a function type must have a name
|
|
correctionMessage: Try providing a name for the parameter or removing the curly braces.
|
|
hasPublishedDocs: false
|
|
missingNameInLibraryDirective:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Library directives must include a library name.
|
|
correctionMessage: "Try adding a library name after the keyword 'library', or remove the library directive if the library doesn't have any parts."
|
|
hasPublishedDocs: false
|
|
missingNameInPartOfDirective:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Part-of directives must include a library name.
|
|
correctionMessage: "Try adding a library name after the 'of'."
|
|
hasPublishedDocs: false
|
|
missingStarAfterSync:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The modifier 'sync' must be followed by a star ('*')."
|
|
correctionMessage: Try removing the modifier, or add a star.
|
|
hasPublishedDocs: false
|
|
missingTerminatorForParameterGroup:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the terminator that is missing
|
|
removedIn: "2.12"
|
|
problemMessage: "There is no '#p0' to close the parameter group."
|
|
correctionMessage: "Try inserting a '#p0' at the end of the group."
|
|
hasPublishedDocs: false
|
|
missingTypedefParameters:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Typedefs must have an explicit list of parameters.
|
|
correctionMessage: Try adding a parameter list.
|
|
hasPublishedDocs: false
|
|
missingVariableInForEach:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A loop variable must be declared in a for-each loop before the 'in', but none was found."
|
|
correctionMessage: Try declaring a loop variable.
|
|
hasPublishedDocs: false
|
|
mixedParameterGroups:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Can't have both positional and named parameters in a single parameter list."
|
|
correctionMessage: Try choosing a single style of optional parameters.
|
|
hasPublishedDocs: false
|
|
multipleImplementsClauses:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Each class or mixin definition can have at most one implements clause.
|
|
correctionMessage: Try combining all of the implements clauses into a single clause.
|
|
hasPublishedDocs: false
|
|
multipleNamedParameterGroups:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Can't have multiple groups of named parameters in a single parameter list."
|
|
correctionMessage: Try combining all of the groups into a single group.
|
|
hasPublishedDocs: false
|
|
multiplePositionalParameterGroups:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Can't have multiple groups of positional parameters in a single parameter list."
|
|
correctionMessage: Try combining all of the groups into a single group.
|
|
hasPublishedDocs: false
|
|
multipleRepresentationFields:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Each extension type should have exactly one representation field.
|
|
correctionMessage: Try combining fields into a record, or removing extra fields.
|
|
hasPublishedDocs: false
|
|
multipleVariablesInForEach:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the number of variables being declared
|
|
removedIn: "2.12"
|
|
problemMessage: "A single loop variable must be declared in a for-each loop before the 'in', but #p0 were found."
|
|
correctionMessage: Try moving all but one of the declarations inside the loop body.
|
|
hasPublishedDocs: false
|
|
namedFunctionExpression:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Function expressions can't be named."
|
|
correctionMessage: Try removing the name, or moving the function expression to a function declaration statement.
|
|
hasPublishedDocs: false
|
|
namedFunctionType:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Function types can't be named."
|
|
correctionMessage: "Try replacing the name with the keyword 'Function'."
|
|
hasPublishedDocs: false
|
|
namedParameterOutsideGroup:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Named parameters must be enclosed in curly braces ('{' and '}')."
|
|
correctionMessage: Try surrounding the named parameters in curly braces.
|
|
hasPublishedDocs: false
|
|
nativeClauseInNonSdkCode:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Native clause can only be used in the SDK and code that is loaded through native extensions.
|
|
correctionMessage: Try removing the native clause.
|
|
hasPublishedDocs: false
|
|
nativeFunctionBodyInNonSdkCode:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Native functions can only be declared in the SDK and code that is loaded through native extensions.
|
|
correctionMessage: "Try removing the word 'native'."
|
|
hasPublishedDocs: false
|
|
nonConstructorFactory:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Only a constructor can be declared to be a factory.
|
|
correctionMessage: "Try removing the keyword 'factory'."
|
|
hasPublishedDocs: false
|
|
nonIdentifierLibraryName:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: The name of a library must be an identifier.
|
|
correctionMessage: Try using an identifier as the name of the library.
|
|
hasPublishedDocs: false
|
|
nonPartOfDirectiveInPart:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: The part-of directive must be the only directive in a part.
|
|
correctionMessage: Try removing the other directives, or moving them to the library for which this is a part.
|
|
hasPublishedDocs: false
|
|
nonStringLiteralAsUri:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: The URI must be a string literal.
|
|
correctionMessage: Try enclosing the URI in either single or double quotes.
|
|
hasPublishedDocs: false
|
|
nonUserDefinableOperator:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the operator that the user is trying to define
|
|
removedIn: "2.12"
|
|
problemMessage: "The operator '#p0' isn't user definable."
|
|
hasPublishedDocs: false
|
|
normalBeforeOptionalParameters:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Normal parameters must occur before optional parameters.
|
|
correctionMessage: Try moving all of the normal parameters before the optional parameters.
|
|
hasPublishedDocs: false
|
|
partOfName:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The 'part of' directive can't use a name with the enhanced-parts feature."
|
|
correctionMessage: "Try using 'part of' with a URI instead."
|
|
hasPublishedDocs: false
|
|
positionalAfterNamedArgument:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Positional arguments must occur before named arguments.
|
|
correctionMessage: Try moving all of the positional arguments before the named arguments.
|
|
hasPublishedDocs: false
|
|
positionalParameterOutsideGroup:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Positional parameters must be enclosed in square brackets ('[' and ']')."
|
|
correctionMessage: Try surrounding the positional parameters in square brackets.
|
|
hasPublishedDocs: false
|
|
privateOptionalParameter:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Named parameters can't start with an underscore."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the name of a named parameter
|
|
starts with an underscore.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the named parameter
|
|
`_x` starts with an underscore:
|
|
|
|
```dart
|
|
// @dart=3.11
|
|
class C {
|
|
void m({int [!_x!] = 0}) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Rename the parameter so that it doesn't start with an underscore:
|
|
|
|
```dart
|
|
class C {
|
|
void m({int x = 0}) {}
|
|
}
|
|
```
|
|
privateNamedNonFieldParameter:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Named parameters that don't refer to instance variables can't start with underscore."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a named parameter starts with
|
|
an underscore, unless it's an initializing formal or field parameter.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the named parameter
|
|
`_x` starts with an underscore:
|
|
|
|
```dart
|
|
class C {
|
|
C({int [!_x!] = 0});
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the parameter is intended to refer to a field, then add the missing
|
|
field:
|
|
|
|
```dart
|
|
class C {
|
|
final int _x;
|
|
C({this._x = 0});
|
|
int get x => _x;
|
|
}
|
|
```
|
|
|
|
If the parameter isn't intended to refer to a field, then remove the
|
|
underscore:
|
|
|
|
```dart
|
|
class C {
|
|
C({int x = 0});
|
|
}
|
|
```
|
|
representationFieldModifier:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Representation fields can't have the modifier 'var'."
|
|
correctionMessage: Try removing the modifier.
|
|
hasPublishedDocs: false
|
|
representationFieldTrailingComma:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: The representation field can't have a trailing comma.
|
|
correctionMessage: Try removing the trailing comma.
|
|
hasPublishedDocs: false
|
|
setterInFunction:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Setters can't be defined within methods or functions."
|
|
correctionMessage: Try moving the setter outside the method or function.
|
|
hasPublishedDocs: false
|
|
staticGetterWithoutBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A 'static' getter must have a body."
|
|
correctionMessage: "Try adding a body to the getter, or removing the keyword 'static'."
|
|
hasPublishedDocs: false
|
|
staticSetterWithoutBody:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "A 'static' setter must have a body."
|
|
correctionMessage: "Try adding a body to the setter, or removing the keyword 'static'."
|
|
hasPublishedDocs: false
|
|
unexpectedTerminatorForParameterGroup:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the starting character that was missing
|
|
removedIn: "2.12"
|
|
problemMessage: "There is no '#p0' to open a parameter group."
|
|
correctionMessage: "Try inserting the '#p0' at the appropriate location."
|
|
hasPublishedDocs: false
|
|
unexpectedToken:
|
|
type: syntacticError
|
|
parameters:
|
|
String text: the unexpected text that was found
|
|
problemMessage: "Unexpected text '#text'."
|
|
correctionMessage: Try removing the text.
|
|
hasPublishedDocs: false
|
|
varClass:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Classes can't be declared to be 'var'."
|
|
correctionMessage: "Try removing the keyword 'var'."
|
|
hasPublishedDocs: false
|
|
varEnum:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Enums can't be declared to be 'var'."
|
|
correctionMessage: "Try removing the keyword 'var'."
|
|
hasPublishedDocs: false
|
|
varTypedef:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "Typedefs can't be declared to be 'var'."
|
|
correctionMessage: "Try removing the keyword 'var', or replacing it with the name of the return type."
|
|
hasPublishedDocs: false
|
|
wrongNumberOfParametersForSetter:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Setters must declare exactly one required positional parameter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a setter is found that doesn't
|
|
declare exactly one required positional parameter.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the setter `s` declares
|
|
two required parameters:
|
|
|
|
```dart
|
|
class C {
|
|
set [!s!](int x, int y) {}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the setter `s` declares
|
|
one optional parameter:
|
|
|
|
```dart
|
|
class C {
|
|
set [!s!]([int? x]) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the declaration so that there's exactly one required positional
|
|
parameter:
|
|
|
|
```dart
|
|
class C {
|
|
set s(int x) {}
|
|
}
|
|
```
|
|
wrongSeparatorForPositionalParameter:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: "The default value of a positional parameter should be preceded by '='."
|
|
correctionMessage: "Try replacing the ':' with '='."
|
|
hasPublishedDocs: false
|
|
wrongTerminatorForParameterGroup:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the terminator that was expected
|
|
String p1: the terminator that was found
|
|
removedIn: "2.12"
|
|
problemMessage: "Expected '#p0' to close parameter group."
|
|
correctionMessage: "Try replacing '#p0' with '#p1'."
|
|
hasPublishedDocs: false
|
|
PubspecWarningCode:
|
|
assetDirectoryDoesNotExist:
|
|
type: staticWarning
|
|
parameters:
|
|
String path: the path to the asset directory as given in the file.
|
|
problemMessage: "The asset directory '#path' doesn't exist."
|
|
correctionMessage: Try creating the directory or fixing the path to the directory.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an asset list contains a value
|
|
referencing a directory that doesn't exist.
|
|
|
|
#### Example
|
|
|
|
Assuming that the directory `assets` doesn't exist, the following code
|
|
produces this diagnostic because it's listed as a directory containing
|
|
assets:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- [!assets/!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the path is correct, then create a directory at that path.
|
|
|
|
If the path isn't correct, then change the path to match the path of the
|
|
directory containing the assets.
|
|
assetDoesNotExist:
|
|
type: staticWarning
|
|
parameters:
|
|
String path: the path to the asset as given in the file.
|
|
problemMessage: "The asset file '#path' doesn't exist."
|
|
correctionMessage: Try creating the file or fixing the path to the file.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an asset list contains a value
|
|
referencing a file that doesn't exist.
|
|
|
|
#### Example
|
|
|
|
Assuming that the file `doesNotExist.gif` doesn't exist, the following code
|
|
produces this diagnostic because it's listed as an asset:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- [!doesNotExist.gif!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the path is correct, then create a file at that path.
|
|
|
|
If the path isn't correct, then change the path to match the path of the
|
|
file containing the asset.
|
|
assetFieldNotList:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The value of the 'assets' field is expected to be a list of relative file paths."
|
|
correctionMessage: Try converting the value to be a list of relative file paths.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of the `assets` key
|
|
isn't a list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the
|
|
`assets` key is a string when a list is expected:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets: [!assets/!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the value of the asset list so that it's a list:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- assets/
|
|
```
|
|
assetMissingPath:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Asset map entry must contain a 'path' field."
|
|
correctionMessage: "Try adding a 'path' field."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an asset map is missing a
|
|
`path` value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the asset map
|
|
is missing a `path` value:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- flavors:
|
|
- premium
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the asset map so that it contains a `path` field with a string
|
|
value (a valid POSIX-style file path):
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- path: assets/image.gif
|
|
flavors:
|
|
- premium
|
|
```
|
|
assetNotString:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Assets are required to be file paths (strings).
|
|
correctionMessage: Try converting the value to be a string.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This code is deprecated in favor of the
|
|
'ASSET_NOT_STRING_OR_MAP' code, and will be removed.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `assets` list contains a
|
|
value that isn't a string.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `assets` list
|
|
contains a map:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- [!image.gif: true!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the `assets` list so that it only contains valid POSIX-style file
|
|
paths:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- assets/image.gif
|
|
```
|
|
assetNotStringOrMap:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: An asset value is required to be a file path (string) or map.
|
|
correctionMessage: Try converting the value to be a string or map.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an asset value isn't a string
|
|
or a map.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the asset value
|
|
is a list:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- [![one, two, three]!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to specify more than just the path to the asset, then replace
|
|
the value with a map with a `path` key (a valid POSIX-style file path):
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- path: assets/image.gif
|
|
flavors:
|
|
- premium
|
|
```
|
|
|
|
If you only need to specify the path, then replace the value with the path
|
|
to the asset (a valid POSIX-style file path):
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- assets/image.gif
|
|
```
|
|
assetPathNotString:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Asset paths are required to be file paths (strings).
|
|
correctionMessage: Try converting the value to be a string.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an asset map contains a
|
|
`path` value that isn't a string.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the asset map
|
|
contains a `path` value which is a list:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- path: [![one, two, three]!]
|
|
flavors:
|
|
- premium
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the `asset` map so that it contains a `path` value which is a
|
|
string (a valid POSIX-style file path):
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
assets:
|
|
- path: image.gif
|
|
flavors:
|
|
- premium
|
|
```
|
|
dependenciesFieldNotMap:
|
|
type: staticWarning
|
|
parameters:
|
|
String fieldName: the name of the field
|
|
problemMessage: "The value of the '#fieldName' field is expected to be a map."
|
|
correctionMessage: Try converting the value to be a map.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of either the
|
|
`dependencies` or `dev_dependencies` key isn't a map.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the
|
|
top-level `dependencies` key is a list:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
[!- meta!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use a map as the value of the `dependencies` key:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
```
|
|
deprecatedField:
|
|
type: staticWarning
|
|
parameters:
|
|
String fieldName: the name of the field
|
|
problemMessage: "The '#fieldName' field is no longer used and can be removed."
|
|
correctionMessage: Try removing the field.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key is used in a
|
|
`pubspec.yaml` file that was deprecated. Unused keys take up space and
|
|
might imply semantics that are no longer valid.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `author` key is no
|
|
longer being used:
|
|
|
|
```dart
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
author: 'Dash'
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the deprecated key:
|
|
|
|
```dart
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
```
|
|
flutterFieldNotMap:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The value of the 'flutter' field is expected to be a map."
|
|
correctionMessage: Try converting the value to be a map.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of the `flutter` key
|
|
isn't a map.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the
|
|
top-level `flutter` key is a string:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter: [!true!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to specify Flutter-specific options, then change the value to
|
|
be a map:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
flutter:
|
|
uses-material-design: true
|
|
```
|
|
|
|
If you don't need to specify Flutter-specific options, then remove the
|
|
`flutter` key:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
```
|
|
invalidDependency:
|
|
type: staticWarning
|
|
parameters:
|
|
String kind: the kind of dependency.
|
|
problemMessage: "Publishable packages can't have '#kind' dependencies."
|
|
correctionMessage: "Try adding a 'publish_to: none' entry to mark the package as not for publishing or remove the #kind dependency."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a publishable package
|
|
includes a package in the `dependencies` list of its `pubspec.yaml` file
|
|
that isn't a pub-hosted dependency.
|
|
|
|
To learn more about the different types of dependency sources,
|
|
check out [Package dependencies](https://dart.dev/tools/pub/dependencies).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the dependency on
|
|
the package `transmogrify` isn't a pub-hosted dependency.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
transmogrify:
|
|
[!path!]: ../transmogrify
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you want to publish the package to `pub.dev`, then change
|
|
the dependency to a hosted package that is published on `pub.dev`.
|
|
|
|
If the package isn't intended to be published on `pub.dev`, then
|
|
add a `publish_to: none` entry to its `pubspec.yaml` file to
|
|
mark it as not intended to be published:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
publish_to: none
|
|
dependencies:
|
|
transmogrify:
|
|
path: ../transmogrify
|
|
```
|
|
invalidPlatformsField:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The 'platforms' field must be a map with platforms as keys."
|
|
correctionMessage: "Try changing the 'platforms' field to a map with platforms as keys."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a top-level `platforms`
|
|
field is specified, but its value is not a map with keys.
|
|
To learn more about specifying your package's supported platforms,
|
|
check out the [documentation on platform declarations](https://dart.dev/tools/pub/pubspec#platforms).
|
|
|
|
#### Example
|
|
|
|
The following `pubspec.yaml` produces this diagnostic because `platforms`
|
|
should be a map.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
platforms:
|
|
[!- android
|
|
- web
|
|
- ios!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can rely on automatic platform detection, then omit the
|
|
top-level `platforms` field.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
```
|
|
|
|
If you need to manually specify the list of supported platforms, then
|
|
write the `platforms` field as a map with platform names as keys.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
platforms:
|
|
android:
|
|
web:
|
|
ios:
|
|
```
|
|
unknownPlatform:
|
|
type: staticWarning
|
|
parameters:
|
|
String platform: the unknown platform.
|
|
problemMessage: "The platform '#platform' is not a recognized platform."
|
|
correctionMessage: "Try correcting the platform name or removing it."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an unknown platform name is
|
|
used as a key in the `platforms` map.
|
|
To learn more about specifying your package's supported platforms,
|
|
check out the [documentation on platform declarations](https://dart.dev/tools/pub/pubspec#platforms).
|
|
|
|
#### Example
|
|
|
|
The following `pubspec.yaml` produces this diagnostic because the platform
|
|
`browser` is unknown.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
platforms:
|
|
[!browser:!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you can rely on automatic platform detection, then omit the
|
|
top-level `platforms` key.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
```
|
|
|
|
If you need to manually specify the list of supported platforms, then
|
|
write the `platforms` field as a map with known platform names as keys.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
platforms:
|
|
# These are the known platforms
|
|
android:
|
|
ios:
|
|
linux:
|
|
macos:
|
|
web:
|
|
windows:
|
|
```
|
|
platformValueDisallowed:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Keys in the `platforms` field can't have values."
|
|
correctionMessage: "Try removing the value, while keeping the key."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key in the `platforms` map
|
|
has a value.
|
|
To learn more about specifying your package's supported platforms,
|
|
check out the [documentation on platform declarations](https://dart.dev/tools/pub/pubspec#platforms).
|
|
|
|
#### Example
|
|
|
|
The following `pubspec.yaml` produces this diagnostic because the key
|
|
`web` has a value.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
platforms:
|
|
web: [!"chrome"!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Omit the value and leave the key without a value:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
platforms:
|
|
web:
|
|
```
|
|
|
|
Values for keys in the `platforms` field are currently reserved for
|
|
potential future behavior.
|
|
missingName:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The 'name' field is required but missing."
|
|
correctionMessage: "Try adding a field named 'name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's no top-level `name` key.
|
|
The `name` key provides the name of the package, which is required.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the package doesn't
|
|
have a name:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the top-level key `name` with a value that's the name of the package:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
```
|
|
missingDependency:
|
|
type: staticWarning
|
|
parameters:
|
|
String missing: description of the missing packages, and which section of the pubspec file they are missing from.
|
|
String fix: description of what to fix
|
|
problemMessage: "Missing a dependency on imported #missing."
|
|
correctionMessage: "Try adding #fix."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a package that has been
|
|
imported in the source but is not listed as a dependency of the
|
|
importing package.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the package `path` is
|
|
not listed as a dependency, while there is an import statement
|
|
with package `path` in the source code of package `example`:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the missing package `path` to the `dependencies` field:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
path: any
|
|
```
|
|
nameNotString:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The value of the 'name' field is required to be a string."
|
|
correctionMessage: Try converting the value to be a string.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the top-level `name` key has a
|
|
value that isn't a string.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value following the
|
|
`name` key is a list:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name:
|
|
[!- example!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the value with a string:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
```
|
|
pathDoesNotExist:
|
|
type: staticWarning
|
|
parameters:
|
|
String path: the path to the dependency as given in the file.
|
|
problemMessage: "The path '#path' doesn't exist."
|
|
correctionMessage: Try creating the referenced path or using a path that exists.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a dependency has a `path` key
|
|
referencing a directory that doesn't exist.
|
|
|
|
#### Example
|
|
|
|
Assuming that the directory `doesNotExist` doesn't exist, the following
|
|
code produces this diagnostic because it's listed as the path of a package:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
local_package:
|
|
path: [!doesNotExist!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the path is correct, then create a directory at that path.
|
|
|
|
If the path isn't correct, then change the path to match the path to the
|
|
root of the package.
|
|
pathNotPosix:
|
|
type: staticWarning
|
|
parameters:
|
|
String path: the path as given in the file.
|
|
problemMessage: "The path '#path' isn't a POSIX-style path."
|
|
correctionMessage: Try converting the value to a POSIX-style path.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a dependency has a `path` key
|
|
whose value is a string, but isn't a POSIX-style path.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the path following the
|
|
`path` key is a Windows path:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
local_package:
|
|
path: [!E:\local_package!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Convert the path to a POSIX path.
|
|
pathPubspecDoesNotExist:
|
|
type: staticWarning
|
|
parameters:
|
|
String path: the path to the dependency as given in the file.
|
|
problemMessage: "The directory '#path' doesn't contain a pubspec."
|
|
correctionMessage: Try creating a pubspec in the referenced directory or using a path that has a pubspec.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a dependency has a `path` key
|
|
that references a directory that doesn't contain a `pubspec.yaml` file.
|
|
|
|
#### Example
|
|
|
|
Assuming that the directory `local_package` doesn't contain a file
|
|
`pubspec.yaml`, the following code produces this diagnostic because it's
|
|
listed as the path of a package:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
local_package:
|
|
path: [!local_package!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the path is intended to be the root of a package, then add a
|
|
`pubspec.yaml` file in the directory:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: local_package
|
|
```
|
|
|
|
If the path is wrong, then replace it with the correct path.
|
|
unnecessaryDevDependency:
|
|
type: staticWarning
|
|
parameters:
|
|
String package: the name of the package in the dev_dependency list.
|
|
problemMessage: "The dev dependency on #package is unnecessary because there is also a normal dependency on that package."
|
|
correctionMessage: Try removing the dev dependency.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's an entry under
|
|
`dev_dependencies` for a package that is also listed under `dependencies`.
|
|
The packages under `dependencies` are available to all of the code in the
|
|
package, so there's no need to also list them under `dev_dependencies`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the package `meta` is
|
|
listed under both `dependencies` and `dev_dependencies`:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
dev_dependencies:
|
|
[!meta!]: ^1.0.2
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the entry under `dev_dependencies` (and the `dev_dependencies` key
|
|
if that's the only package listed there):
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
dependencies:
|
|
meta: ^1.0.2
|
|
```
|
|
workspaceFieldNotList:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The value of the 'workspace' field is required to be a list of relative file paths."
|
|
correctionMessage: Try converting the value to be a list of relative file paths.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of the `workspace` key
|
|
isn't a list.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the
|
|
`workspace` key is a string when a list is expected:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
workspace: [!notPaths!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the value of the workspace field so that it's a list:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
workspace:
|
|
- pkg/package_1
|
|
- pkg/package_2
|
|
```
|
|
|
|
workspaceValueNotString:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Workspace entries are required to be directory paths (strings).
|
|
correctionMessage: Try converting the value to be a string.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `workspace` list contains a
|
|
value that isn't a string.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `workspace` list
|
|
contains a map:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
workspace:
|
|
- [!image.gif: true!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the `workspace` list so that it only contains valid POSIX-style directory
|
|
paths:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
workspace:
|
|
- pkg/package_1
|
|
- pkg/package_2
|
|
```
|
|
|
|
workspaceValueNotSubdirectory:
|
|
type: staticWarning
|
|
parameters:
|
|
String path: the path of the directory that contains the pubspec.yaml file.
|
|
problemMessage: Workspace values must be a relative path of a subdirectory of '#path'.
|
|
correctionMessage: Try using a subdirectory of the directory containing the 'pubspec.yaml' file.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `workspace` list contains a
|
|
value that is not a subdirectory of the directory containing the `pubspec.yaml`` file.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value in the `workspace` list is not a
|
|
relative path of a subdirectory of the directory containing the 'pubspec.yaml' file:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
workspace:
|
|
- /home/my_package
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the `workspace` list so that it only contains only subdirectory paths.
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
name: example
|
|
workspace:
|
|
- pkg/package_1
|
|
- pkg/package_2
|
|
```
|
|
ScannerErrorCode:
|
|
encoding:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Unable to decode bytes as UTF-8.
|
|
hasPublishedDocs: false
|
|
illegalCharacter:
|
|
type: syntacticError
|
|
parameters:
|
|
int codePoint: the illegal character
|
|
problemMessage: Illegal character '#codePoint'.
|
|
hasPublishedDocs: false
|
|
missingDigit:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Decimal digit expected.
|
|
hasPublishedDocs: false
|
|
missingHexDigit:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Hexadecimal digit expected.
|
|
hasPublishedDocs: false
|
|
missingQuote:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Expected quote (' or ").
|
|
hasPublishedDocs: false
|
|
unableGetContent:
|
|
type: syntacticError
|
|
parameters:
|
|
String p0: the path of the file that cannot be read
|
|
removedIn: "2.6"
|
|
problemMessage: Unable to get content of '#p0'.
|
|
hasPublishedDocs: false
|
|
unawaitedReturnInTryBlock:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Returning a 'Future' without 'await' inside a try block."
|
|
correctionMessage: "Try adding an 'await'."
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `Future` is returned from within
|
|
a `try` block, in an `async` function, without awaiting the returned `Future`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `Future` returned
|
|
from `futureString` is returned without using `await`. This can lead to
|
|
unexpected behavior because exceptions thrown by the `Future` won't be
|
|
caught by the `catch` block.
|
|
|
|
```dart
|
|
Future<String> futureString(Future<String> value) async {
|
|
try {
|
|
[!return!] value;
|
|
} catch (e) {
|
|
print(e);
|
|
return 'default';
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add `await` before the returned `Future`:
|
|
|
|
```dart
|
|
Future<String> futureString(Future<String> value) async {
|
|
try {
|
|
return await value;
|
|
} catch (e) {
|
|
print(e);
|
|
return 'default';
|
|
}
|
|
}
|
|
```
|
|
unexpectedDollarInString:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: A '$' has special meaning inside a string, and must be followed by an identifier or an expression in curly braces ({}).
|
|
hasPublishedDocs: false
|
|
correctionMessage: Try adding a backslash (\) to escape the '$'.
|
|
unexpectedSeparatorInNumber:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Digit separators ('_') in a number literal can only be placed between two digits.
|
|
hasPublishedDocs: false
|
|
correctionMessage: Try removing the '_'.
|
|
unsupportedOperator:
|
|
type: syntacticError
|
|
parameters:
|
|
String lexeme: the unsupported operator
|
|
problemMessage: The '#lexeme' operator is not supported.
|
|
hasPublishedDocs: false
|
|
unterminatedMultiLineComment:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Unterminated multi-line comment.
|
|
hasPublishedDocs: false
|
|
correctionMessage: Try terminating the comment with '*/', or removing any unbalanced occurrences of '/*' (because comments nest in Dart).
|
|
unterminatedStringLiteral:
|
|
type: syntacticError
|
|
parameters: none
|
|
problemMessage: Unterminated string literal.
|
|
hasPublishedDocs: false
|
|
StaticWarningCode:
|
|
deadNullAwareExpression:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The left operand can't be null, so the right operand is never executed."
|
|
correctionMessage: Try removing the operator and the right operand.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic in two cases.
|
|
|
|
The first is when the left operand of an `??` operator can't be `null`.
|
|
The right operand is only evaluated if the left operand has the value
|
|
`null`, and because the left operand can't be `null`, the right operand is
|
|
never evaluated.
|
|
|
|
The second is when the left-hand side of an assignment using the `??=`
|
|
operator can't be `null`. The right-hand side is only evaluated if the
|
|
left-hand side has the value `null`, and because the left-hand side can't
|
|
be `null`, the right-hand side is never evaluated.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `x` can't be `null`:
|
|
|
|
```dart
|
|
%ignore=dead_code
|
|
int f(int x) {
|
|
return x ?? [!0!];
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `f` can't be `null`:
|
|
|
|
```dart
|
|
%ignore=dead_code
|
|
class C {
|
|
int f = -1;
|
|
|
|
void m(int x) {
|
|
f ??= [!x!];
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the diagnostic is reported for an `??` operator, then remove the `??`
|
|
operator and the right operand:
|
|
|
|
```dart
|
|
int f(int x) {
|
|
return x;
|
|
}
|
|
```
|
|
|
|
If the diagnostic is reported for an assignment, and the assignment isn't
|
|
needed, then remove the assignment:
|
|
|
|
```dart
|
|
class C {
|
|
int f = -1;
|
|
|
|
void m(int x) {
|
|
}
|
|
}
|
|
```
|
|
|
|
If the assignment is needed, but should be based on a different condition,
|
|
then rewrite the code to use `=` and the different condition:
|
|
|
|
```dart
|
|
class C {
|
|
int f = -1;
|
|
|
|
void m(int x) {
|
|
if (f < 0) {
|
|
f = x;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
invalidNullAwareOperator:
|
|
type: staticWarning
|
|
parameters:
|
|
String operator: the null-aware operator that is invalid
|
|
String replacement: the non-null-aware operator that can replace the invalid operator
|
|
problemMessage: "The receiver can't be null, so the null-aware operator '#operator' is unnecessary."
|
|
correctionMessage: "Try replacing the operator '#operator' with '#replacement'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a null-aware operator (`?.`,
|
|
`?..`, `?[`, `?..[`, or `...?`) is used on a receiver that's known to be
|
|
non-nullable.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `s` can't be `null`:
|
|
|
|
```dart
|
|
int? getLength(String s) {
|
|
return s[!?.!]length;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `a` can't be `null`:
|
|
|
|
```dart
|
|
var a = [];
|
|
var b = [[!...?!]a];
|
|
```
|
|
|
|
The following code produces this diagnostic because `s?.length` can't
|
|
return `null`:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
s?.length[!?.!]isEven;
|
|
}
|
|
```
|
|
|
|
The reason `s?.length` can't return `null` is because the null-aware
|
|
operator following `s` short-circuits the evaluation of both `length` and
|
|
`isEven` if `s` is `null`. In other words, if `s` is `null`, then neither
|
|
`length` nor `isEven` will be invoked, and if `s` is non-`null`, then
|
|
`length` can't return a `null` value. Either way, `isEven` can't be invoked
|
|
on a `null` value, so the null-aware operator isn't necessary. See
|
|
[Understanding null safety](/null-safety/understanding-null-safety#smarter-null-aware-methods)
|
|
for more details.
|
|
|
|
The following code produces this diagnostic because `s` can't be `null`.
|
|
|
|
```dart
|
|
void f(Object? o) {
|
|
var s = o as String;
|
|
s[!?.!]length;
|
|
}
|
|
```
|
|
|
|
The reason `s` can't be null, despite the fact that `o` can be `null`, is
|
|
because of the cast to `String`, which is a non-nullable type. If `o` ever
|
|
has the value `null`, the cast will fail and the invocation of `length`
|
|
will not happen.
|
|
|
|
The following code produces this diagnostic because `s` can't be `null`:
|
|
|
|
```dart
|
|
List<String> makeSingletonList(String s) {
|
|
return <String>[[!?!]s];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the null-aware operator with a non-null-aware equivalent; for
|
|
example, change `?.` to `.`:
|
|
|
|
```dart
|
|
int getLength(String s) {
|
|
return s.length;
|
|
}
|
|
```
|
|
|
|
(Note that the return type was also changed to be non-nullable, which might
|
|
not be appropriate in some cases.)
|
|
invalidNullAwareOperatorAfterShortCircuit:
|
|
type: staticWarning
|
|
parameters:
|
|
String operator: the null-aware operator that is invalid
|
|
String replacement: the non-null-aware operator that can replace the invalid operator
|
|
sharedName: invalidNullAwareOperator
|
|
problemMessage: "The receiver can't be 'null' because of short-circuiting, so the null-aware operator '#operator' can't be used."
|
|
correctionMessage: "Try replacing the operator '#operator' with '#replacement'."
|
|
hasPublishedDocs: true
|
|
invalidNullAwareElement:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidNullAwareOperator
|
|
problemMessage: "The element can't be null, so the null-aware operator '?' is unnecessary."
|
|
correctionMessage: "Try removing the operator '?'."
|
|
hasPublishedDocs: true
|
|
invalidNullAwareMapEntryKey:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidNullAwareOperator
|
|
problemMessage: "The map entry key can't be null, so the null-aware operator '?' is unnecessary."
|
|
correctionMessage: "Try removing the operator '?'."
|
|
hasPublishedDocs: true
|
|
invalidNullAwareMapEntryValue:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidNullAwareOperator
|
|
problemMessage: "The map entry value can't be null, so the null-aware operator '?' is unnecessary."
|
|
correctionMessage: "Try removing the operator '?'."
|
|
hasPublishedDocs: true
|
|
missingEnumConstantInSwitch:
|
|
type: staticWarning
|
|
parameters:
|
|
String constant: the name of the constant that is missing
|
|
problemMessage: "Missing case clause for '#constant'."
|
|
correctionMessage: Try adding a case clause for the missing constant, or adding a default clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `switch` statement for an enum
|
|
doesn't include an option for one of the values in the enum.
|
|
|
|
Note that `null` is always a possible value for an enum and therefore also
|
|
must be handled.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the enum value `e2`
|
|
isn't handled:
|
|
|
|
```dart
|
|
%language=2.19
|
|
enum E { e1, e2 }
|
|
|
|
void f(E e) {
|
|
[!switch (e)!] {
|
|
case E.e1:
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If there's special handling for the missing values, then add a `case`
|
|
clause for each of the missing values:
|
|
|
|
```dart
|
|
enum E { e1, e2 }
|
|
|
|
void f(E e) {
|
|
switch (e) {
|
|
case E.e1:
|
|
break;
|
|
case E.e2:
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the missing values should be handled the same way, then add a `default`
|
|
clause:
|
|
|
|
```dart
|
|
enum E { e1, e2 }
|
|
|
|
void f(E e) {
|
|
switch (e) {
|
|
case E.e1:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
```
|
|
TODO(brianwilkerson): This documentation will need to be updated when NNBD
|
|
ships.
|
|
unnecessaryNonNullAssertion:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The '!' will have no effect because the receiver can't be null."
|
|
correctionMessage: "Try removing the '!' operator."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the operand of the `!` operator
|
|
can't be `null`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `x` can't be `null`:
|
|
|
|
```dart
|
|
int f(int x) {
|
|
return x[!!!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the null check operator (`!`):
|
|
|
|
```dart
|
|
int f(int x) {
|
|
return x;
|
|
}
|
|
```
|
|
unnecessaryNullAssertPattern:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: The null-assert pattern will have no effect because the matched type isn't nullable.
|
|
correctionMessage: Try replacing the null-assert pattern with its nested pattern.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a null-assert pattern is used
|
|
to match a value that isn't nullable.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the variable `x` isn't
|
|
nullable:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var a[!!!] when a > 0) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the null-assert pattern:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var a when a > 0) {}
|
|
}
|
|
```
|
|
unnecessaryNullCheckPattern:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: The null-check pattern will have no effect because the matched type isn't nullable.
|
|
correctionMessage: Try replacing the null-check pattern with its nested pattern.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a null-check pattern is used to
|
|
match a value that isn't nullable.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value `x` isn't
|
|
nullable:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var a[!?!] when a > 0) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the null-check pattern:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var a when a > 0) {}
|
|
}
|
|
```
|
|
TodoCode:
|
|
fixme:
|
|
type: todo
|
|
parameters:
|
|
String message: the user-supplied problem message
|
|
problemMessage: "#message"
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A TODO comment marked as FIXME.
|
|
hack:
|
|
type: todo
|
|
parameters:
|
|
String message: the user-supplied problem message
|
|
problemMessage: "#message"
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A TODO comment marked as HACK.
|
|
todo:
|
|
type: todo
|
|
parameters:
|
|
String message: the user-supplied problem message
|
|
problemMessage: "#message"
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A standard TODO comment marked as TODO.
|
|
undone:
|
|
type: todo
|
|
parameters:
|
|
String message: the user-supplied problem message
|
|
problemMessage: "#message"
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
A TODO comment marked as UNDONE.
|
|
WarningCode:
|
|
argumentTypeNotAssignableToErrorHandler:
|
|
type: staticWarning
|
|
parameters:
|
|
Type actualType: the name of the actual argument type
|
|
Type expectedType: the name of the expected function return type
|
|
problemMessage: "The argument type '#actualType' can't be assigned to the parameter type '#expectedType Function(Object)' or '#expectedType Function(Object, StackTrace)'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of
|
|
`Future.catchError` has an argument that is a function whose parameters
|
|
aren't compatible with the arguments that will be passed to the function
|
|
when it's invoked. The static type of the first argument to `catchError`
|
|
is just `Function`, even though the function that is passed in is expected
|
|
to have either a single parameter of type `Object` or two parameters of
|
|
type `Object` and `StackTrace`.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the closure being
|
|
passed to `catchError` doesn't take any parameters, but the function is
|
|
required to take at least one parameter:
|
|
|
|
```dart
|
|
void f(Future<int> f) {
|
|
f.catchError([!() => 0!]);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the closure being
|
|
passed to `catchError` takes three parameters, but it can't have more than
|
|
two required parameters:
|
|
|
|
```dart
|
|
void f(Future<int> f) {
|
|
f.catchError([!(one, two, three) => 0!]);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because even though the closure
|
|
being passed to `catchError` takes one parameter, the closure doesn't have
|
|
a type that is compatible with `Object`:
|
|
|
|
```dart
|
|
void f(Future<int> f) {
|
|
f.catchError([!(String error) => 0!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the function being passed to `catchError` so that it has either one
|
|
or two required parameters, and the parameters have the required types:
|
|
|
|
```dart
|
|
void f(Future<int> f) {
|
|
f.catchError((Object error) => 0);
|
|
}
|
|
```
|
|
assignmentOfDoNotStore:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the field or variable
|
|
problemMessage: "'#name' is marked 'doNotStore' and shouldn't be assigned to a field or top-level variable."
|
|
correctionMessage: Try removing the assignment.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Users should not assign values marked `@doNotStore`.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of a function
|
|
(including methods and getters) that is explicitly or implicitly marked by
|
|
the [`doNotStore`][meta-doNotStore] annotation is stored in either a field
|
|
or top-level variable.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of the
|
|
function `f` is being stored in the top-level variable `x`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@doNotStore
|
|
int f() => 1;
|
|
|
|
var x = [!f()!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace references to the field or variable with invocations of the
|
|
function producing the value.
|
|
bodyMightCompleteNormallyCatchError:
|
|
type: staticWarning
|
|
parameters:
|
|
Type type: the return type as derived by the type of the [Future].
|
|
problemMessage: "This 'onError' handler must return a value assignable to '#type', but ends without returning a value."
|
|
correctionMessage: Try adding a return statement.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the closure passed to the
|
|
`onError` parameter of the `Future.catchError` method is required to
|
|
return a non-`null` value (because of the `Future`s type argument) but can
|
|
implicitly return `null`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the closure passed to
|
|
the `catchError` method is required to return an `int` but doesn't end
|
|
with an explicit `return`, causing it to implicitly return `null`:
|
|
|
|
```dart
|
|
void g(Future<int> f) {
|
|
f.catchError((e, st) [!{!]});
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the closure should sometimes return a non-`null` value, then add an
|
|
explicit return to the closure:
|
|
|
|
```dart
|
|
void g(Future<int> f) {
|
|
f.catchError((e, st) {
|
|
return -1;
|
|
});
|
|
}
|
|
```
|
|
|
|
If the closure should always return `null`, then change the type argument
|
|
of the `Future` to be either `void` or `Null`:
|
|
|
|
```dart
|
|
void g(Future<void> f) {
|
|
f.catchError((e, st) {});
|
|
}
|
|
```
|
|
bodyMightCompleteNormallyNullable:
|
|
type: staticWarning
|
|
parameters:
|
|
Type returnType: the name of the declared return type
|
|
problemMessage: "This function has a nullable return type of '#returnType', but ends without returning a value."
|
|
correctionMessage: "Try adding a return statement, or if no value is ever returned, try changing the return type to 'void'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function can
|
|
implicitly return `null` by falling off the end. While this is valid Dart
|
|
code, it's better for the return of `null` to be explicit.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `f`
|
|
implicitly returns `null`:
|
|
|
|
```dart
|
|
String? [!f!]() {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the return of `null` is intentional, then make it explicit:
|
|
|
|
```dart
|
|
String? f() {
|
|
return null;
|
|
}
|
|
```
|
|
|
|
If the function should return a non-null value along that path, then add
|
|
the missing return statement:
|
|
|
|
```dart
|
|
String? f() {
|
|
return '';
|
|
}
|
|
```
|
|
castFromNullAlwaysFails:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "This cast always throws an exception because the expression always evaluates to 'null'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an expression whose type is
|
|
`Null` is being cast to a non-nullable type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `n` is known to always
|
|
be `null`, but it's being cast to a non-nullable type:
|
|
|
|
```dart
|
|
void f(Null n) {
|
|
[!n as int!];
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary cast:
|
|
|
|
```dart
|
|
void f(Null n) {
|
|
n;
|
|
}
|
|
```
|
|
castFromNullableAlwaysFails:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the unassigned variable
|
|
problemMessage: "This cast will always throw an exception because the nullable local variable '#name' is not assigned."
|
|
correctionMessage: "Try giving it an initializer expression, or ensure that it's assigned on every execution path."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a local variable that has a
|
|
nullable type hasn't been assigned and is cast to a non-nullable type.
|
|
Because the variable hasn't been assigned it has the default value of
|
|
`null`, causing the cast to throw an exception.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the variable `x` is
|
|
cast to a non-nullable type (`int`) when it's known to have the value
|
|
`null`:
|
|
|
|
```dart
|
|
void f() {
|
|
num? x;
|
|
[!x!] as int;
|
|
print(x);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the variable is expected to have a value before the cast, then add an
|
|
initializer or an assignment:
|
|
|
|
```dart
|
|
void f() {
|
|
num? x = 3;
|
|
x as int;
|
|
print(x);
|
|
}
|
|
```
|
|
|
|
If the variable isn't expected to be assigned, then remove the cast:
|
|
|
|
```dart
|
|
void f() {
|
|
num? x;
|
|
print(x);
|
|
}
|
|
```
|
|
constantPatternNeverMatchesValueType:
|
|
type: staticWarning
|
|
parameters:
|
|
Type matchedType: the matched value type
|
|
Type constantType: the constant value type
|
|
problemMessage: "The matched value type '#matchedType' can never be equal to this constant of type '#constantType'."
|
|
correctionMessage: "Try a constant of the same type as the matched value type."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constant pattern can never
|
|
match the value it's being tested against because the type of the constant
|
|
is known to never match the type of the value.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the type of the
|
|
constant pattern `(true)` is `bool`, and the type of the value being
|
|
matched (`x`) is `int`, and a Boolean can never match an integer:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case [!true!]) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type of the value is correct, then rewrite the pattern to be
|
|
compatible:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case 3) {}
|
|
}
|
|
```
|
|
|
|
If the type of the constant is correct, then rewrite the value to be
|
|
compatible:
|
|
|
|
```dart
|
|
void f(bool x) {
|
|
if (x case true) {}
|
|
}
|
|
```
|
|
deadCode:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Dead code.
|
|
correctionMessage: Try removing the code, or fixing the code before it so that it can be reached.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Dead code is code that is never reached, this can happen for instance if a
|
|
statement follows a return statement.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when code is found that won't be
|
|
executed because execution will never reach the code.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the invocation of
|
|
`print` occurs after the function has returned:
|
|
|
|
```dart
|
|
void f() {
|
|
return;
|
|
[!print('here');!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the code isn't needed, then remove it:
|
|
|
|
```dart
|
|
void f() {
|
|
return;
|
|
}
|
|
```
|
|
|
|
If the code needs to be executed, then either move the code to a place
|
|
where it will be executed:
|
|
|
|
```dart
|
|
void f() {
|
|
print('here');
|
|
return;
|
|
}
|
|
```
|
|
|
|
Or, rewrite the code before it, so that it can be reached:
|
|
|
|
```dart
|
|
void f({bool skipPrinting = true}) {
|
|
if (skipPrinting) {
|
|
return;
|
|
}
|
|
print('here');
|
|
}
|
|
```
|
|
deadCodeCatchFollowingCatch:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Dead code: Catch clauses after a 'catch (e)' or an 'on Object catch (e)' are never reached."
|
|
correctionMessage: Try reordering the catch clauses so that they can be reached, or removing the unreachable catch clauses.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Dead code is code that is never reached. This case covers cases where the
|
|
user has catch clauses after `catch (e)` or `on Object catch (e)`.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `catch` clause is found that
|
|
can't be executed because it's after a `catch` clause of the form
|
|
`catch (e)` or `on Object catch (e)`. The first `catch` clause that matches
|
|
the thrown object is selected, and both of those forms will match any
|
|
object, so no `catch` clauses that follow them will be selected.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
} catch (e) {
|
|
} [!on String {
|
|
}!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the clause should be selectable, then move the clause before the general
|
|
clause:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
} on String {
|
|
} catch (e) {
|
|
}
|
|
}
|
|
```
|
|
|
|
If the clause doesn't need to be selectable, then remove it:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
} catch (e) {
|
|
}
|
|
}
|
|
```
|
|
deadCodeLateWildcardVariableInitializer:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Dead code: The assigned-to wildcard variable is marked late and can never be referenced so this initializer will never be evaluated."
|
|
correctionMessage: Try removing the code, removing the late modifier or changing the variable to a non-wildcard.
|
|
sharedName: deadCode
|
|
hasPublishedDocs: true
|
|
deadCodeOnCatchSubtype:
|
|
type: staticWarning
|
|
parameters:
|
|
Type subtype: name of the subtype
|
|
Type supertype: name of the supertype
|
|
problemMessage: "Dead code: This on-catch block won't be executed because '#subtype' is a subtype of '#supertype' and hence will have been caught already."
|
|
correctionMessage: Try reordering the catch clauses so that this block can be reached, or removing the unreachable catch clause.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Dead code is code that is never reached. This case covers cases where the
|
|
user has an on-catch clause such as `on A catch (e)`, where a supertype of
|
|
`A` was already caught.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `catch` clause is found that
|
|
can't be executed because it is after a `catch` clause that catches either
|
|
the same type or a supertype of the clause's type. The first `catch` clause
|
|
that matches the thrown object is selected, and the earlier clause always
|
|
matches anything matchable by the highlighted clause, so the highlighted
|
|
clause will never be selected.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
} on num {
|
|
} [!on int {
|
|
}!]
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the clause should be selectable, then move the clause before the general
|
|
clause:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
} on int {
|
|
} on num {
|
|
}
|
|
}
|
|
```
|
|
|
|
If the clause doesn't need to be selectable, then remove it:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
} on num {
|
|
}
|
|
}
|
|
```
|
|
deprecatedExportUse:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the element
|
|
problemMessage: "The ability to import '#name' indirectly is deprecated."
|
|
correctionMessage: "Try importing '#name' directly."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when one library imports a name from
|
|
a second library, and the second library exports the name from a third
|
|
library but has indicated that it won't export the third library in the
|
|
future.
|
|
|
|
#### Example
|
|
|
|
Given a library `a.dart` defining the class `A`:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
class A {}
|
|
```
|
|
|
|
And a second library `b.dart` that exports `a.dart` but has marked the
|
|
export as being deprecated:
|
|
|
|
```dart
|
|
%uri="lib/b.dart"
|
|
import 'a.dart';
|
|
|
|
@deprecated
|
|
export 'a.dart';
|
|
```
|
|
|
|
The following code produces this diagnostic because the class `A` won't be
|
|
exported from `b.dart` in some future version:
|
|
|
|
```dart
|
|
import 'b.dart';
|
|
|
|
[!A!]? a;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name is available from a different library that you can import,
|
|
then replace the existing import with an import for that library (or add
|
|
an import for the defining library if you still need the old import):
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
A? a;
|
|
```
|
|
|
|
If the name isn't available, then look for instructions from the library
|
|
author or contact them directly to find out how to update your code.
|
|
deprecatedExtend:
|
|
type: staticWarning
|
|
parameters:
|
|
String typeName: the name of the type
|
|
problemMessage: "Extending '#typeName' is deprecated."
|
|
correctionMessage: Try removing the 'extends' clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class annotated with
|
|
`@Deprecated.extend` is used in the `extends` clause of a class
|
|
declaration.
|
|
|
|
This annotation indicates that the ability to extend the annotated class
|
|
is deprecated and will soon be removed. This change will likely be
|
|
enforced by marking the class with `interface`, `final`, or `sealed`.
|
|
|
|
#### Example
|
|
|
|
If the library `p` defines a class annotated with `@Deprecated.extend`:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
@Deprecated.extend()
|
|
class C {}
|
|
```
|
|
|
|
Then, in any library other than `p`, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
class D extends [!C!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Follow any directions found in the `Deprecation.extend` annotation.
|
|
Otherwise, remove the `extends` clause.
|
|
|
|
```dart
|
|
class D {}
|
|
```
|
|
deprecatedExtendsFunction:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: deprecatedSubtypeOfFunction
|
|
problemMessage: "Extending 'Function' is deprecated."
|
|
correctionMessage: "Try removing 'Function' from the 'extends' clause."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the class `Function` is used in
|
|
either the `extends`, `implements`, or `with` clause of a class or mixin.
|
|
Using the class `Function` in this way has no semantic value, so it's
|
|
effectively dead code.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `Function` is used as
|
|
the superclass of `F`:
|
|
|
|
```dart
|
|
class F extends [!Function!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the class `Function` from whichever clause it's in, and remove the
|
|
whole clause if `Function` is the only type in the clause:
|
|
|
|
```dart
|
|
class F {}
|
|
```
|
|
deprecatedFactoryMethod:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Methods named 'factory' will become constructors when the primary_constructors feature is enabled.
|
|
correctionMessage: Try adding a return type or modifier before the method's name, or change the name of the method.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the declaration of an instance
|
|
method named `factory` is interpreted as a constructor declaration after
|
|
the `primary_constructors` feature is enabled.
|
|
|
|
This issue only affects declarations that lack a return type and where the
|
|
method name is the first token or is preceded only by `external`,
|
|
`augment`, or `augment external`. The `augment` and `augment external`
|
|
keywords are valid only after the augmentations feature is enabled.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the instance method
|
|
named `factory` has no return type or modifiers:
|
|
|
|
```dart
|
|
// @dart=3.10
|
|
class C {
|
|
[!factory!]() => C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name can be changed, then rename the method:
|
|
|
|
```dart
|
|
// @dart=3.10
|
|
class C {
|
|
make() => C();
|
|
}
|
|
```
|
|
|
|
If the name must remain `factory`, then add a return type:
|
|
|
|
```dart
|
|
// @dart=3.10
|
|
class C {
|
|
C factory() => C();
|
|
}
|
|
```
|
|
deprecatedImplement:
|
|
type: staticWarning
|
|
parameters:
|
|
String typeName: the name of the type
|
|
problemMessage: "Implementing '#typeName' is deprecated."
|
|
correctionMessage: Try removing '#typeName' from the 'implements' clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class annotated with
|
|
`@Deprecated.implement` is used in the `implements` clause of a class or
|
|
enum declaration. This annotation indicates that the ability to implement
|
|
the annotated class is deprecated and will soon be removed. This change
|
|
will likely be enforced by marking the class with `interface`, `final`, or
|
|
`sealed`.
|
|
|
|
#### Example
|
|
|
|
If the library `p` defines a class annotated with `@Deprecated.implement`:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
@Deprecated.implement()
|
|
class C {}
|
|
```
|
|
|
|
Then, in any library other than `p`, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
class D implements [!C!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Follow any directions found in the `Deprecation.implement` annotation.
|
|
Otherwise, remove the `implements` clause.
|
|
|
|
```dart
|
|
class D {}
|
|
```
|
|
deprecatedImplementsFunction:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: deprecatedSubtypeOfFunction
|
|
problemMessage: "Implementing 'Function' has no effect."
|
|
correctionMessage: "Try removing 'Function' from the 'implements' clause."
|
|
hasPublishedDocs: true
|
|
deprecatedInstantiate:
|
|
type: staticWarning
|
|
parameters:
|
|
String typeName: the name of the type
|
|
problemMessage: "Instantiating '#typeName' is deprecated."
|
|
correctionMessage: Try instantiating a non-abstract class.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class annotated with
|
|
`@Deprecated.instantiate` is instantiated. This annotation indicates that
|
|
instantiating the class is deprecated and will soon be removed. This
|
|
change will likely be enforced by marking the class as `abstract` or
|
|
`sealed`.
|
|
|
|
#### Example
|
|
|
|
If the library `p` defines a class annotated with
|
|
`@Deprecated.instantiate`:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
@Deprecated.instantiate()
|
|
class C {}
|
|
```
|
|
|
|
Then, in any library other than `p`, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
var c = [!C!]();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Follow any directions found in the `Deprecation.instantiate` annotation.
|
|
deprecatedMixin:
|
|
type: staticWarning
|
|
parameters:
|
|
String typeName: the name of the type
|
|
problemMessage: "Mixing in '#typeName' is deprecated."
|
|
correctionMessage: Try removing '#typeName' from the 'with' clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a mixin class annotated with
|
|
`@Deprecated.mixin` is used in the `with` clause of a class or enum
|
|
declaration. This annotation indicates that using the annotated mixin is
|
|
deprecated and will soon be removed. This change will likely be enforced
|
|
by removing the `mixin` class modifier.
|
|
|
|
#### Example
|
|
|
|
If the library `p` defines a class annotated with `@Deprecated.mixin`:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
@Deprecated.mixin()
|
|
mixin class C {}
|
|
```
|
|
|
|
Then, in any library other than `p`, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
class D with [!C!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Follow any directions found in the `Deprecation.mixin` annotation.
|
|
Otherwise, remove the mixin class name from the `with` clause.
|
|
|
|
```dart
|
|
class D {}
|
|
```
|
|
deprecatedMixinFunction:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: deprecatedSubtypeOfFunction
|
|
problemMessage: "Mixing in 'Function' is deprecated."
|
|
correctionMessage: "Try removing 'Function' from the 'with' clause."
|
|
hasPublishedDocs: true
|
|
deprecatedOptional:
|
|
type: staticWarning
|
|
parameters:
|
|
String parameterName: the name of the parameter
|
|
problemMessage: "Omitting an argument for the '#parameterName' parameter is deprecated."
|
|
correctionMessage: Try passing an argument for '#parameterName'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an argument is omitted for an
|
|
optional parameter annotated with `@Deprecated.optional`. This annotation
|
|
indicates that omitting an argument for the parameter is deprecated, and
|
|
the parameter will soon become required.
|
|
|
|
#### Example
|
|
|
|
Given a library `p` that defines a function with an optional parameter
|
|
annotated with `@Deprecated.optional`:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
void f({@Deprecated.optional() int a = 0}) {}
|
|
```
|
|
|
|
The following code produces this diagnostic, because the invocation
|
|
doesn't pass a value for the parameter `a`:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
void g() {
|
|
[!f!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Follow any specific instructions provided in the `@Deprecated.optional`
|
|
annotation.
|
|
|
|
If no instructions are present, pass an appropriate argument for the
|
|
corresponding parameter:
|
|
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
void g() {
|
|
f(a: 0);
|
|
}
|
|
```
|
|
|
|
Using the default value will preserve the current behavior of the code.
|
|
deprecatedNewInCommentReference:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Using the 'new' keyword in a comment reference is deprecated."
|
|
correctionMessage: Try referring to a constructor by its name.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a comment reference (the name
|
|
of a declaration enclosed in square brackets in a documentation comment)
|
|
uses the keyword `new` to refer to a constructor. This form is deprecated.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the unnamed
|
|
constructor is being referenced using `new C`:
|
|
|
|
```dart
|
|
/// See [[!new!] C].
|
|
class C {
|
|
C();
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the constructor named
|
|
`c` is being referenced using `new C.c`:
|
|
|
|
```dart
|
|
/// See [[!new!] C.c].
|
|
class C {
|
|
C.c();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you're referencing a named constructor, then remove the keyword `new`:
|
|
|
|
```dart
|
|
/// See [C.c].
|
|
class C {
|
|
C.c();
|
|
}
|
|
```
|
|
|
|
If you're referencing the unnamed constructor, then remove the keyword
|
|
`new` and append `.new` after the class name:
|
|
|
|
```dart
|
|
/// See [C.new].
|
|
class C {
|
|
C.c();
|
|
}
|
|
```
|
|
deprecatedSubclass:
|
|
type: staticWarning
|
|
parameters:
|
|
String typeName: the name of the type
|
|
problemMessage: "Subclassing '#typeName' is deprecated."
|
|
correctionMessage: Try removing the 'extends' clause, or removing '#typeName' from the 'implements' clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class annotated with
|
|
`@Deprecated.subclass` is used in the `extends` clause of a class
|
|
declaration, or the `implements` clause of a class or enum declaration.
|
|
|
|
This annotation indicates that extending or implementing the annotated
|
|
class is deprecated and will soon be removed. This change will likely be
|
|
enforced by marking the class with `final` or `sealed`.
|
|
|
|
#### Example
|
|
|
|
If the library `p` defines a class annotated with `@Deprecated.subclass`:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
@Deprecated.subclass()
|
|
class C {}
|
|
```
|
|
|
|
Then, in any library other than `p`, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
class D extends [!C!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Follow any specific instructions provided in the `@Deprecated.subclass`
|
|
annotation. Otherwise, remove the relevant `extends` clause or remove the
|
|
class name from the `implements` clause:
|
|
|
|
```dart
|
|
class D {}
|
|
```
|
|
docDirectiveHasExtraArguments:
|
|
type: staticWarning
|
|
parameters:
|
|
String directive: the name of the doc directive
|
|
int actualCount: the actual number of arguments
|
|
int expectedCount: the expected number of arguments
|
|
problemMessage: "The '#directive' directive has '#actualCount' arguments, but only '#expectedCount' are expected."
|
|
correctionMessage: Try removing the extra arguments.
|
|
hasPublishedDocs: false
|
|
docDirectiveHasUnexpectedNamedArgument:
|
|
type: staticWarning
|
|
parameters:
|
|
String directive: the name of the doc directive
|
|
String argumentName: the name of the unexpected argument
|
|
problemMessage: "The '#directive' directive has an unexpected named argument, '#argumentName'."
|
|
correctionMessage: "Try removing the unexpected argument."
|
|
hasPublishedDocs: false
|
|
docDirectiveMissingClosingBrace:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Doc directive is missing a closing curly brace ('}')."
|
|
correctionMessage: "Try closing the directive with a curly brace."
|
|
hasPublishedDocs: false
|
|
docDirectiveMissingClosingTag:
|
|
type: staticWarning
|
|
parameters:
|
|
String tagName: the name of the corresponding doc directive tag
|
|
problemMessage: "Doc directive is missing a closing tag."
|
|
correctionMessage: "Try closing the directive with the appropriate closing tag, '#tagName'."
|
|
hasPublishedDocs: false
|
|
docDirectiveMissingOneArgument:
|
|
type: staticWarning
|
|
parameters:
|
|
String directive: the name of the doc directive
|
|
String argumentName: the name of the missing argument
|
|
sharedName: docDirectiveMissingArgument
|
|
problemMessage: "The '#directive' directive is missing a '#argumentName' argument."
|
|
correctionMessage: "Try adding a '#argumentName' argument before the closing '}'."
|
|
hasPublishedDocs: false
|
|
docDirectiveArgumentWrongFormat:
|
|
type: staticWarning
|
|
parameters:
|
|
String argumentName: the name of the doc directive argument
|
|
String expectedFormat: the expected format
|
|
problemMessage: "The '#argumentName' argument must be formatted as #expectedFormat."
|
|
correctionMessage: "Try formatting '#argumentName' as #expectedFormat."
|
|
hasPublishedDocs: false
|
|
docDirectiveMissingOpeningTag:
|
|
type: staticWarning
|
|
parameters:
|
|
String tagName: the name of the corresponding doc directive tag
|
|
problemMessage: "Doc directive is missing an opening tag."
|
|
correctionMessage: "Try opening the directive with the appropriate opening tag, '#tagName'."
|
|
hasPublishedDocs: false
|
|
docDirectiveMissingThreeArguments:
|
|
type: staticWarning
|
|
parameters:
|
|
String directive: the name of the doc directive
|
|
String argument1: the name of the first missing argument
|
|
String argument2: the name of the second missing argument
|
|
String argument3: the name of the third missing argument
|
|
sharedName: docDirectiveMissingArgument
|
|
problemMessage: "The '#directive' directive is missing a '#argument1', a '#argument2', and a '#argument3' argument."
|
|
correctionMessage: "Try adding the missing arguments before the closing '}'."
|
|
hasPublishedDocs: false
|
|
docDirectiveMissingTwoArguments:
|
|
type: staticWarning
|
|
parameters:
|
|
String directive: the name of the doc directive
|
|
String argument1: the name of the first missing argument
|
|
String argument2: the name of the second missing argument
|
|
sharedName: docDirectiveMissingArgument
|
|
problemMessage: "The '#directive' directive is missing a '#argument1' and a '#argument2' argument."
|
|
correctionMessage: "Try adding the missing arguments before the closing '}'."
|
|
hasPublishedDocs: false
|
|
docDirectiveUnknown:
|
|
type: staticWarning
|
|
parameters:
|
|
String directive: the name of the unknown doc directive.
|
|
problemMessage: "Doc directive '#directive' is unknown."
|
|
correctionMessage: "Try using one of the supported doc directives."
|
|
hasPublishedDocs: false
|
|
docImportCannotBeDeferred:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Doc imports can't be deferred."
|
|
correctionMessage: Try removing the 'deferred' keyword.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a documentation import uses the
|
|
`deferred` keyword.
|
|
|
|
Documentation imports can't be deferred because deferring them wouldn't
|
|
impact the size of the compiled code.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the documentation
|
|
import has a `deferred` keyword:
|
|
|
|
```dart
|
|
// ignore:missing_prefix_in_deferred_import
|
|
/// @docImport 'package:meta/meta.dart' [!deferred!];
|
|
library;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the `deferred` keyword:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart';
|
|
library;
|
|
```
|
|
docImportCannotHaveCombinators:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Doc imports can't have show or hide combinators."
|
|
correctionMessage: Try removing the combinator.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a documentation import has one
|
|
or more `hide` or `show` combinators.
|
|
|
|
Using combinators isn't supported for documentation imports.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the documentation
|
|
import has a `show` combinator:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart' [!show max!];
|
|
library;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the `hide` and `show` combinators:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart';
|
|
library;
|
|
```
|
|
docImportCannotHaveConfigurations:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Doc imports can't have configurations."
|
|
correctionMessage: Try removing the configurations.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a documentation import has one
|
|
or more `if` clauses.
|
|
|
|
Documentation imports aren't configurable.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the documentation
|
|
import has an `if` clause:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart' [!if (dart.library.io) 'dart:io'!];
|
|
library;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the `if` clauses:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart';
|
|
library;
|
|
```
|
|
docImportCannotHavePrefix:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Doc imports can't have prefixes."
|
|
correctionMessage: Try removing the prefix.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a documentation import has a
|
|
prefix.
|
|
|
|
Using prefixes isn't supported for documentation imports.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the documentation
|
|
import declares a prefix:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart' as [!a!];
|
|
library;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the prefix:
|
|
|
|
```dart
|
|
/// @docImport 'package:meta/meta.dart';
|
|
library;
|
|
```
|
|
duplicateExport:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Duplicate export.
|
|
correctionMessage: Try removing all but one export of the library.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Duplicate exports.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an export directive is found
|
|
that is the same as an export before it in the file. The second export
|
|
doesn't add value and should be removed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the same library is
|
|
being exported twice:
|
|
|
|
```dart
|
|
export 'package:meta/meta.dart';
|
|
export [!'package:meta/meta.dart'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary export:
|
|
|
|
```dart
|
|
export 'package:meta/meta.dart';
|
|
```
|
|
duplicateHiddenName:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Duplicate hidden name.
|
|
correctionMessage: Try removing the repeated name from the list of hidden members.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name occurs multiple times in
|
|
a `hide` clause. Repeating the name is unnecessary.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `min` is
|
|
hidden more than once:
|
|
|
|
```dart
|
|
import 'dart:math' hide min, [!min!];
|
|
|
|
var x = pi;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name was mistyped in one or more places, then correct the mistyped
|
|
names:
|
|
|
|
```dart
|
|
import 'dart:math' hide max, min;
|
|
|
|
var x = pi;
|
|
```
|
|
|
|
If the name wasn't mistyped, then remove the unnecessary name from the
|
|
list:
|
|
|
|
```dart
|
|
import 'dart:math' hide min;
|
|
|
|
var x = pi;
|
|
```
|
|
duplicateIgnore:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the diagnostic being ignored
|
|
problemMessage: "The diagnostic '#name' doesn't need to be ignored here because it's already being ignored."
|
|
correctionMessage: Try removing the name from the list, or removing the whole comment if this is the only name in the list.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a diagnostic name appears in an
|
|
`ignore` comment, but the diagnostic is already being ignored, either
|
|
because it's already included in the same `ignore` comment or because it
|
|
appears in an `ignore-in-file` comment.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the diagnostic named
|
|
`unused_local_variable` is already being ignored for the whole file so it
|
|
doesn't need to be ignored on a specific line:
|
|
|
|
```dart
|
|
// ignore_for_file: unused_local_variable
|
|
void f() {
|
|
// ignore: [!unused_local_variable!]
|
|
var x = 0;
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the diagnostic named
|
|
`unused_local_variable` is being ignored twice on the same line:
|
|
|
|
```dart
|
|
void f() {
|
|
// ignore: unused_local_variable, [!unused_local_variable!]
|
|
var x = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the ignore comment, or remove the unnecessary diagnostic name if the
|
|
ignore comment is ignoring more than one diagnostic:
|
|
|
|
```dart
|
|
// ignore_for_file: unused_local_variable
|
|
void f() {
|
|
var x = 0;
|
|
}
|
|
```
|
|
duplicateImport:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Duplicate import.
|
|
correctionMessage: Try removing all but one import of the library.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Duplicate imports.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import directive is found
|
|
that is the same as an import before it in the file. The second import
|
|
doesn't add value and should be removed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
import [!'package:meta/meta.dart'!];
|
|
|
|
@sealed class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary import:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@sealed class C {}
|
|
```
|
|
duplicateShownName:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Duplicate shown name.
|
|
correctionMessage: Try removing the repeated name from the list of shown members.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a name occurs multiple times in
|
|
a `show` clause. Repeating the name is unnecessary.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the name `min` is shown
|
|
more than once:
|
|
|
|
```dart
|
|
import 'dart:math' show min, [!min!];
|
|
|
|
var x = min(2, min(0, 1));
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the name was mistyped in one or more places, then correct the mistyped
|
|
names:
|
|
|
|
```dart
|
|
import 'dart:math' show max, min;
|
|
|
|
var x = max(2, min(0, 1));
|
|
```
|
|
|
|
If the name wasn't mistyped, then remove the unnecessary name from the
|
|
list:
|
|
|
|
```dart
|
|
import 'dart:math' show min;
|
|
|
|
var x = min(2, min(0, 1));
|
|
```
|
|
equalElementsInSet:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Two elements in a set literal shouldn't be equal."
|
|
correctionMessage: Change or remove the duplicate element.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an element in a non-constant set
|
|
is the same as a previous element in the same set. If two elements are the
|
|
same, then the second value is ignored, which makes having both elements
|
|
pointless and likely signals a bug.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the element `1` appears
|
|
twice:
|
|
|
|
```dart
|
|
const a = 1;
|
|
const b = 1;
|
|
var s = <int>{a, [!b!]};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If both elements should be included in the set, then change one of the
|
|
elements:
|
|
|
|
```dart
|
|
const a = 1;
|
|
const b = 2;
|
|
var s = <int>{a, b};
|
|
```
|
|
|
|
If only one of the elements is needed, then remove the one that isn't
|
|
needed:
|
|
|
|
```dart
|
|
const a = 1;
|
|
var s = <int>{a};
|
|
```
|
|
|
|
Note that literal sets preserve the order of their elements, so the choice
|
|
of which element to remove might affect the order in which elements are
|
|
returned by an iterator.
|
|
equalKeysInMap:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Two keys in a map literal shouldn't be equal."
|
|
correctionMessage: Change or remove the duplicate key.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a key in a non-constant map is
|
|
the same as a previous key in the same map. If two keys are the same, then
|
|
the second value overwrites the first value, which makes having both pairs
|
|
pointless and likely signals a bug.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the keys `a` and `b`
|
|
have the same value:
|
|
|
|
```dart
|
|
const a = 1;
|
|
const b = 1;
|
|
var m = <int, String>{a: 'a', [!b!]: 'b'};
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If both entries should be included in the map, then change one of the keys:
|
|
|
|
```dart
|
|
const a = 1;
|
|
const b = 2;
|
|
var m = <int, String>{a: 'a', b: 'b'};
|
|
```
|
|
|
|
If only one of the entries is needed, then remove the one that isn't
|
|
needed:
|
|
|
|
```dart
|
|
const a = 1;
|
|
var m = <int, String>{a: 'a'};
|
|
```
|
|
|
|
Note that literal maps preserve the order of their entries, so the choice
|
|
of which entry to remove might affect the order in which the keys and
|
|
values are returned by an iterator.
|
|
experimentalMemberUse:
|
|
type: staticWarning
|
|
parameters:
|
|
String member: the name of the member
|
|
problemMessage: "'#member' is experimental and could be removed or changed at any time."
|
|
hasPublishedDocs: false
|
|
inferenceFailureOnCollectionLiteral:
|
|
type: staticWarning
|
|
parameters:
|
|
String collection: the name of the collection
|
|
problemMessage: "The type argument(s) of '#collection' can't be inferred."
|
|
correctionMessage: "Use explicit type argument(s) for '#collection'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" is enabled, collection literal types must be
|
|
inferred via the context type, or have type arguments.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when:
|
|
- the language option `strict-inference` is enabled in the analysis
|
|
options file,
|
|
- a list, map, or set literal has no type arguments, and
|
|
- the values for the type arguments can't be inferred from the elements.
|
|
|
|
#### Example
|
|
|
|
Given an analysis options file containing the following:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
analyzer:
|
|
language:
|
|
strict-inference: true
|
|
```
|
|
|
|
The following code produces this diagnostic because the type of the list
|
|
literal's elements can't be inferred:
|
|
|
|
```dart
|
|
void f() {
|
|
var list = [![]!];
|
|
print(list);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Provide explicit type arguments for the literal:
|
|
|
|
```dart
|
|
void f() {
|
|
var list = <int>[];
|
|
print(list);
|
|
}
|
|
```
|
|
inferenceFailureOnFunctionInvocation:
|
|
type: staticWarning
|
|
parameters:
|
|
String function: the name of the function
|
|
problemMessage: "The type argument(s) of the function '#function' can't be inferred."
|
|
correctionMessage: "Use explicit type argument(s) for '#function'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" is enabled, types in function invocations must be
|
|
inferred via the context type, or have type arguments.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when:
|
|
- the language option `strict-inference` is enabled in the analysis
|
|
options file,
|
|
- the invocation of a method or function has no type arguments, and
|
|
- the values for the type arguments can't be inferred.
|
|
|
|
#### Example
|
|
|
|
Given an analysis options file containing the following:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
analyzer:
|
|
language:
|
|
strict-inference: true
|
|
```
|
|
|
|
The following code produces this diagnostic because the invocation of `m`
|
|
has no explicit type arguments, and the arguments can't be inferred:
|
|
|
|
```dart
|
|
abstract class C {
|
|
void m<T>();
|
|
}
|
|
|
|
void f(C c) {
|
|
c.[!m!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Provide explicit type arguments for the invocation:
|
|
|
|
```dart
|
|
abstract class C {
|
|
void m<T>();
|
|
}
|
|
|
|
void f(C c) {
|
|
c.m<int>();
|
|
}
|
|
```
|
|
inferenceFailureOnFunctionReturnType:
|
|
type: staticWarning
|
|
parameters:
|
|
String function: the name of the function or method whose return type
|
|
can't be inferred
|
|
problemMessage: "The return type of '#function' can't be inferred."
|
|
correctionMessage: "Declare the return type of '#function'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" is enabled, recursive local functions, top-level
|
|
functions, methods, and function-typed function parameters must all
|
|
specify a return type. See the strict-inference resource:
|
|
|
|
https://github.com/dart-lang/language/blob/master/resources/type-system/strict-inference.md
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when:
|
|
- the language option `strict-inference` is enabled in the analysis
|
|
options file,
|
|
- the declaration of a method or function has no return type, and
|
|
- the return type can't be inferred.
|
|
|
|
#### Example
|
|
|
|
Given an analysis options file containing the following:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
analyzer:
|
|
language:
|
|
strict-inference: true
|
|
```
|
|
|
|
The following code produces this diagnostic because the method `m` doesn't
|
|
have a return type:
|
|
|
|
```dart
|
|
class C {
|
|
[!m!]() => 7;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add a return type to the method or function:
|
|
|
|
```dart
|
|
class C {
|
|
int m() => 7;
|
|
}
|
|
```
|
|
inferenceFailureOnGenericInvocation:
|
|
type: staticWarning
|
|
parameters:
|
|
String function: the name of the type
|
|
problemMessage: "The type argument(s) of the generic function type '#function' can't be inferred."
|
|
correctionMessage: "Use explicit type argument(s) for '#function'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" is enabled, types in function invocations must be
|
|
inferred via the context type, or have type arguments.
|
|
inferenceFailureOnInstanceCreation:
|
|
type: staticWarning
|
|
parameters:
|
|
String function: the name of the constructor
|
|
problemMessage: "The type argument(s) of the constructor '#function' can't be inferred."
|
|
correctionMessage: "Use explicit type argument(s) for '#function'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" is enabled, types in instance creation
|
|
(constructor calls) must be inferred via the context type, or have type
|
|
arguments.
|
|
inferenceFailureOnUninitializedVariable:
|
|
type: staticWarning
|
|
parameters:
|
|
String variable: the name of the variable
|
|
problemMessage: "The type of '#variable' can't be inferred without either a type or initializer."
|
|
correctionMessage: Try specifying the type of the variable.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" in enabled, uninitialized variables must be
|
|
declared with a specific type.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when:
|
|
- the language option `strict-inference` is enabled in the analysis
|
|
options file,
|
|
- the declaration of a variable has no type, and
|
|
- the type of the variable can't be inferred.
|
|
|
|
#### Example
|
|
|
|
Given an analysis options file containing the following:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
analyzer:
|
|
language:
|
|
strict-inference: true
|
|
```
|
|
|
|
The following code produces this diagnostic because the variable `s`
|
|
doesn't have an explicit type and the type can't be inferred because
|
|
there's no initializer:
|
|
|
|
```dart
|
|
var [!s!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an explicit type:
|
|
|
|
```dart
|
|
String? s;
|
|
```
|
|
inferenceFailureOnUntypedParameter:
|
|
type: staticWarning
|
|
parameters:
|
|
String parameter: the name of the parameter
|
|
problemMessage: "The type of '#parameter' can't be inferred; a type must be explicitly provided."
|
|
correctionMessage: Try specifying the type of the parameter.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
When "strict-inference" in enabled, function parameters must be
|
|
declared with a specific type, or inherit a type.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when:
|
|
- the language option `strict-inference` is enabled in the analysis
|
|
options file,
|
|
- the declaration of a formal parameter has no type, and
|
|
- the type of the parameter can't be inferred.
|
|
|
|
The type of a method's parameter can be inferred if it overrides an
|
|
inherited method.
|
|
|
|
#### Example
|
|
|
|
Given an analysis options file containing the following:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
analyzer:
|
|
language:
|
|
strict-inference: true
|
|
```
|
|
|
|
The following code produces this diagnostic because the formal parameter
|
|
`p` doesn't have an explicit type and the type can't be inferred:
|
|
|
|
```dart
|
|
void f([!p!]) => print(p);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an explicit type:
|
|
|
|
```dart
|
|
void f(int p) => print(p);
|
|
```
|
|
invalidAnnotationTarget:
|
|
type: staticWarning
|
|
parameters:
|
|
String annotationName: the name of the annotation
|
|
String validTargets: the list of valid targets
|
|
problemMessage: "The annotation '#annotationName' can only be used on #validTargets."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an annotation is applied to a
|
|
kind of declaration that it doesn't support.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `optionalTypeArgs`
|
|
annotation isn't defined to be valid for top-level variables:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@[!optionalTypeArgs!]
|
|
int x = 0;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation from the declaration.
|
|
invalidAwaitNotRequiredAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation 'awaitNotRequired' can only be applied to a Future-returning function, or a Future-typed field."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when anything other than a
|
|
`Future`-returning function or a `Future`-typed field or top-level
|
|
variable is annotated with [`awaitNotRequired`][meta-awaitNotRequired].
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
`void`-returning function:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@[!awaitNotRequired!]
|
|
void f() {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
void f() {}
|
|
```
|
|
invalidDeprecatedExtendAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@Deprecated.extend' can only be applied to extendable classes."
|
|
correctionMessage: Try removing the '@Deprecated.extend' annotation.
|
|
hasPublishedDocs: true
|
|
# TODO(srawlins): link Deprecated.extend below with:
|
|
# [`Deprecated.extend`][meta-deprecated-extend]
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `@Deprecated.extend`
|
|
annotation is applied to a declaration that isn't an extendable class. An
|
|
extendable class is one that isn't declared with the `interface`,
|
|
`final`, or `sealed` keywords and has at least one public, generative
|
|
constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
sealed class:
|
|
|
|
```dart
|
|
@[!Deprecated.extend!]()
|
|
sealed class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
sealed class C {}
|
|
```
|
|
invalidDeprecatedImplementAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@Deprecated.implement' can only be applied to implementable classes."
|
|
correctionMessage: Try removing the '@Deprecated.implement' annotation.
|
|
hasPublishedDocs: true
|
|
# TODO(srawlins): link Deprecated.implement below with:
|
|
# [`Deprecated.implement`][meta-deprecated-implement]
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `@Deprecated.implement`
|
|
annotation is applied to a declaration that isn't an implementable class
|
|
or mixin. An implementable class or mixin is one that isn't declared with
|
|
the base, final, or sealed keywords.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
sealed class:
|
|
|
|
```dart
|
|
@[!Deprecated.implement!]()
|
|
sealed class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
sealed class C {}
|
|
```
|
|
invalidDeprecatedInstantiateAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@Deprecated.instantiate' can only be applied to classes."
|
|
correctionMessage: Try removing the '@Deprecated.instantiate' annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `@Deprecated.instantiate`
|
|
annotation is applied to a declaration that isn't an instantiable class.
|
|
An instantiable class is one that isn't declared with the `abstract` or
|
|
`sealed` keywords and has at least one public, generative constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
sealed class:
|
|
|
|
```dart
|
|
@[!Deprecated.instantiate!]()
|
|
sealed class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
sealed class C {}
|
|
```
|
|
invalidDeprecatedMixinAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@Deprecated.mixin' can only be applied to classes."
|
|
correctionMessage: Try removing the '@Deprecated.mixin' annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where `@Deprecated.mixin` annotates
|
|
something other than a mixin class.
|
|
# TODO(srawlins): link Deprecated.mixin below with:
|
|
# [`Deprecated.mixin`][meta-deprecated-mixin]
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `@Deprecated.mixin`
|
|
annotation is applied to a declaration that isn't a mixin class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
non-mixin class:
|
|
|
|
```dart
|
|
@[!Deprecated.mixin!]()
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
invalidDeprecatedOptionalAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@Deprecated.optional' can only be applied to optional parameters."
|
|
correctionMessage: Try removing the '@Deprecated.optional' annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where `@Deprecated.optional`
|
|
annotates something other than an optional parameter.
|
|
# TODO(srawlins): link Deprecated.optional below with:
|
|
# [`Deprecated.optional`][meta-deprecated-optional]
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `@Deprecated.optional`
|
|
annotation is applied to a parameter that isn't an optional parameter. The
|
|
annotation must not be used on a parameter in a local function, an
|
|
anonymous function, a function-typed parameter, or a typedef. It is only
|
|
valid on optional parameters in a top-level function, a method, or a
|
|
constructor.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
required parameter:
|
|
|
|
```dart
|
|
void f(@[!Deprecated.optional!]() int p) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
void f(int p) {}
|
|
```
|
|
invalidDeprecatedSubclassAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@Deprecated.subclass' can only be applied to subclassable classes and mixins."
|
|
correctionMessage: Try removing the '@Deprecated.subclass' annotation.
|
|
hasPublishedDocs: true
|
|
# TODO(srawlins): link Deprecated.subclass below with:
|
|
# [`Deprecated.subclass`][meta-deprecated-subclass]
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when anything other than a
|
|
subclassable class or mixin is annotated with
|
|
`@Deprecated.subclass`. A subclassable
|
|
class is a class not declared with the `final` or `sealed` keywords. A
|
|
subclassable mixin is a mixin not declared with the `base` keyword.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
sealed class:
|
|
|
|
```dart
|
|
@[!Deprecated.subclass!]()
|
|
sealed class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
sealed class C {}
|
|
```
|
|
invalidExportOfInternalElement:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the element
|
|
problemMessage: "The member '#name' can't be exported as a part of a package's public API."
|
|
correctionMessage: "Try using a hide clause to hide '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a [public library][] exports a
|
|
declaration that is marked with the [`internal`][meta-internal]
|
|
annotation.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` in the `src` directory that contains:
|
|
|
|
```dart
|
|
%uri="lib/src/a.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
@internal class One {}
|
|
```
|
|
|
|
The following code, when found in a [public library][] produces this
|
|
diagnostic because the `export` directive is exporting a name that is only
|
|
intended to be used internally:
|
|
|
|
```dart
|
|
[!export 'src/a.dart';!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the export is needed, then add a `hide` clause to hide the internal
|
|
names:
|
|
|
|
```dart
|
|
export 'src/a.dart' hide One;
|
|
```
|
|
|
|
If the export isn't needed, then remove it.
|
|
invalidExportOfInternalElementIndirectly:
|
|
type: staticWarning
|
|
parameters:
|
|
String internalElementName: the name of the internal element
|
|
String exportedElementName: the name of the exported element that indirectly exposes the internal element
|
|
problemMessage: "The member '#internalElementName' can't be exported as a part of a package's public API, but is indirectly exported as part of the signature of '#exportedElementName'."
|
|
correctionMessage: "Try using a hide clause to hide '#exportedElementName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a [public library][] exports a
|
|
top-level function with a return type or at least one parameter type that
|
|
is marked with the [`internal`][meta-internal] annotation.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` in the `src` directory that contains the
|
|
following:
|
|
|
|
```dart
|
|
%uri="lib/src/a.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
@internal
|
|
typedef IntFunction = int Function();
|
|
|
|
int f(IntFunction g) => g();
|
|
```
|
|
|
|
The following code produces this diagnostic because the function `f` has a
|
|
parameter of type `IntFunction`, and `IntFunction` is only intended to be
|
|
used internally:
|
|
|
|
```dart
|
|
[!export 'src/a.dart' show f;!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the function must be public, then make all the types in the function's
|
|
signature public types.
|
|
|
|
If the function doesn't need to be exported, then stop exporting it,
|
|
either by removing it from the `show` clause, adding it to the `hide`
|
|
clause, or by removing the export.
|
|
invalidFactoryMethodDecl:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: The name of the method
|
|
problemMessage: "Factory method '#name' must have a return type."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method that is annotated with
|
|
the [`factory`][meta-factory] annotation has a return type of `void`.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `createC`
|
|
is annotated with the [`factory`][meta-factory] annotation but doesn't
|
|
return any value:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class Factory {
|
|
@factory
|
|
void [!createC!]() {}
|
|
}
|
|
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the return type to something other than `void`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class Factory {
|
|
@factory
|
|
C createC() => C();
|
|
}
|
|
|
|
class C {}
|
|
```
|
|
invalidFactoryMethodImpl:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the method
|
|
problemMessage: "Factory method '#name' doesn't return a newly allocated object."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method that is annotated with
|
|
the [`factory`][meta-factory] annotation doesn't return a newly allocated
|
|
object.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `createC`
|
|
returns the value of a field rather than a newly created instance of `C`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class Factory {
|
|
C c = C();
|
|
|
|
@factory
|
|
C [!createC!]() => c;
|
|
}
|
|
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the method to return a newly created instance of the return type:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class Factory {
|
|
@factory
|
|
C createC() => C();
|
|
}
|
|
|
|
class C {}
|
|
```
|
|
invalidInternalAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Only public elements in a package's private API can be annotated as being internal."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a declaration is annotated with
|
|
the [`internal`][meta-internal] annotation and that declaration is either
|
|
in a [public library][] or has a private name.
|
|
|
|
#### Example
|
|
|
|
The following code, when in a [public library][], produces this diagnostic
|
|
because the [`internal`][meta-internal] annotation can't be applied to
|
|
declarations in a [public library][]:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@[!internal!]
|
|
class C {}
|
|
```
|
|
|
|
The following code, whether in a public or internal library, produces this
|
|
diagnostic because the [`internal`][meta-internal] annotation can't be
|
|
applied to declarations with private names:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@[!internal!]
|
|
class _C {}
|
|
|
|
void f(_C c) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the declaration has a private name, then remove the annotation:
|
|
|
|
```dart
|
|
class _C {}
|
|
|
|
void f(_C c) {}
|
|
```
|
|
|
|
If the declaration has a public name and is intended to be internal to the
|
|
package, then move the annotated declaration into an internal library (in
|
|
other words, a library inside the `src` directory).
|
|
|
|
Otherwise, remove the use of the annotation:
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
invalidLanguageVersionOverrideGreater:
|
|
type: staticWarning
|
|
parameters:
|
|
int latestMajor: the latest major version
|
|
int latestMinor: the latest minor version
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The language version override can't specify a version greater than the latest known language version: #latestMajor.#latestMinor."
|
|
correctionMessage: Try removing the language version override.
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverrideAtSign:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The Dart language version override number must begin with '@dart'."
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a comment that appears to be an
|
|
attempt to specify a language version override doesn't conform to the
|
|
requirements for such a comment. For more information, see
|
|
[Per-library language version selection](https://dart.dev/resources/language/evolution#per-library-language-version-selection).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the word `dart` must
|
|
be lowercase in such a comment and because there's no equal sign between
|
|
the word `dart` and the version number:
|
|
|
|
```dart
|
|
[!// @Dart 2.13!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the comment is intended to be a language version override, then change
|
|
the comment to follow the correct format:
|
|
|
|
```dart
|
|
// @dart = 2.13
|
|
```
|
|
invalidLanguageVersionOverrideLocation:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: The language version override must be specified before any declaration or directive.
|
|
correctionMessage: Try moving the language version override to the top of the file.
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverrideLowerCase:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The Dart language version override comment must be specified with the word 'dart' in all lower case."
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverrideNumber:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The Dart language version override comment must be specified with a version number, like '2.0', after the '=' character."
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverridePrefix:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The Dart language version override number can't be prefixed with a letter."
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverrideTrailingCharacters:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The Dart language version override comment can't be followed by any non-whitespace characters."
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverrideTwoSlashes:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: The Dart language version override comment must be specified with exactly two slashes.
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
invalidLanguageVersionOverrideEquals:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: invalidLanguageVersionOverride
|
|
problemMessage: "The Dart language version override comment must be specified with an '=' character."
|
|
correctionMessage: "Specify a Dart language version override with a comment like '// @dart = 2.0'."
|
|
hasPublishedDocs: true
|
|
invalidLiteralAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Only const constructors can have the `@literal` annotation.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the [`literal`][meta-literal]
|
|
annotation is applied to anything other than a const constructor.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the constructor isn't
|
|
a `const` constructor:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@[!literal!]
|
|
C();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotation is on a constructor and the constructor should always be
|
|
invoked with `const`, when possible, then mark the constructor with the
|
|
`const` keyword:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@literal
|
|
const C();
|
|
}
|
|
```
|
|
|
|
If the constructor can't be marked as `const`, then remove the annotation.
|
|
|
|
If the annotation is on anything other than a constructor, then remove the
|
|
annotation:
|
|
|
|
```dart
|
|
var x;
|
|
```
|
|
invalidNonVirtualAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@nonVirtual' can only be applied to a concrete instance member."
|
|
correctionMessage: Try removing '@nonVirtual'.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where `@nonVirtual` annotates something
|
|
other than a non-abstract instance member in a class or mixin.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `nonVirtual` annotation is
|
|
found on a declaration other than a member of a class, mixin, or enum, or
|
|
if the member isn't a concrete instance member.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the method `m` is an
|
|
abstract method:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
abstract class C {
|
|
@[!nonVirtual!]
|
|
void m();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the member is intended to be a concrete instance member, then make it
|
|
so:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
abstract class C {
|
|
@nonVirtual
|
|
void m() {}
|
|
}
|
|
```
|
|
invalidOverrideOfNonVirtualMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String memberName: the name of the member
|
|
String definingClass: the name of the defining class
|
|
problemMessage: "The member '#memberName' is declared non-virtual in '#definingClass' and can't be overridden in subclasses."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where an instance member annotated with
|
|
`@nonVirtual` is overridden in a subclass.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member of a class, mixin, or
|
|
enum overrides a member that has the `@nonVirtual` annotation on it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `m` in `B`
|
|
overrides the method `m` in `A`, and the method `m` in `A` is annotated
|
|
with the `@nonVirtual` annotation:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@nonVirtual
|
|
void m() {}
|
|
}
|
|
|
|
class B extends A {
|
|
@override
|
|
void [!m!]() {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotation on the method in the superclass is correct (the method
|
|
in the superclass is not intended to be overridden), then remove or rename
|
|
the overriding method:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@nonVirtual
|
|
void m() {}
|
|
}
|
|
|
|
class B extends A {}
|
|
```
|
|
|
|
If the method in the superclass is intended to be overridden, then remove
|
|
the `@nonVirtual` annotation:
|
|
|
|
```dart
|
|
class A {
|
|
void m() {}
|
|
}
|
|
|
|
class B extends A {
|
|
@override
|
|
void m() {}
|
|
}
|
|
```
|
|
invalidUseOfDoNotSubmitMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the member
|
|
problemMessage: "Uses of '#name' should not be submitted to source control."
|
|
correctionMessage: "Try removing the reference to '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member that is annotated with
|
|
[`@doNotSubmit`][meta-doNotSubmit] is referenced outside of a member
|
|
declaration that is also annotated with `@doNotSubmit`.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` containing the following declaration:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
@doNotSubmit
|
|
void emulateCrash() { /* ... */ }
|
|
```
|
|
|
|
The following code produces this diagnostic because the declaration is
|
|
being referenced outside of a member that is also annotated with
|
|
`@doNotSubmit`:
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
void f() {
|
|
[!emulateCrash!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Most commonly, when complete with local testing, the reference to the
|
|
member should be removed.
|
|
|
|
If building additional functionality on top of the member, annotate the
|
|
newly added member with `@doNotSubmit` as well:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
import 'a.dart';
|
|
|
|
@doNotSubmit
|
|
void emulateCrashWithOtherFunctionality() {
|
|
emulateCrash();
|
|
// do other things.
|
|
}
|
|
```
|
|
invalidUseOfInternalMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the member
|
|
problemMessage: "The member '#name' can only be used within its package."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a reference to a declaration
|
|
that is annotated with the [`internal`][meta-internal] annotation is found
|
|
outside the package containing the declaration.
|
|
|
|
#### Example
|
|
|
|
Given a package `p` that defines a library containing a declaration marked
|
|
with the [`internal`][meta-internal] annotation:
|
|
|
|
```dart
|
|
%uri="package:p/src/p.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
@internal
|
|
class C {}
|
|
```
|
|
|
|
The following code produces this diagnostic because it's referencing the
|
|
class `C`, which isn't intended to be used outside the package `p`:
|
|
|
|
```dart
|
|
import 'package:p/src/p.dart';
|
|
|
|
void f([!C!] c) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the reference to the internal declaration.
|
|
invalidUseOfProtectedMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String memberName: the name of the member
|
|
String definingClass: the name of the defining class
|
|
problemMessage: "The member '#memberName' can only be used within instance members of subclasses of '#definingClass'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where a member annotated with
|
|
`@protected` is used outside of an instance member of a subclass.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a getter, setter, field, or
|
|
method that has been annotated with `@protected` is referenced anywhere
|
|
other than in the library in which it is declared or in a subclass of the
|
|
class in which it is declared.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@protected
|
|
void a() {}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the method `a` is
|
|
being invoked in code that isn't in a subclass of `A`:
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
void b(A a) {
|
|
a.[!a!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If it's reasonable for the member to be marked as `@protected`, then
|
|
remove the reference to the protected member, replacing it with some
|
|
equivalent code.
|
|
|
|
If it isn't reasonable for the member to be marked as `@protected`, and
|
|
you have the ability to do so, remove the annotation.
|
|
invalidUseOfVisibleForOverridingMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the member
|
|
problemMessage: "The member '#name' can only be used for overriding."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an instance member that is
|
|
annotated with [`visibleForOverriding`][meta-visibleForOverriding] is
|
|
referenced outside the library in which it's declared for any reason other
|
|
than to override it.
|
|
|
|
#### Example
|
|
|
|
Given a file `a.dart` containing the following declaration:
|
|
|
|
```dart
|
|
%uri="lib/a.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@visibleForOverriding
|
|
void a() {}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the method `m` is being
|
|
invoked even though the only reason it's public is to allow it to be
|
|
overridden:
|
|
|
|
```dart
|
|
import 'a.dart';
|
|
|
|
class B extends A {
|
|
void b() {
|
|
[!a!]();
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the invalid use of the member.
|
|
invalidUseOfVisibleForTemplateMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String memberName: the name of the member
|
|
Uri uri: the uri of the file containing the defining class
|
|
problemMessage: "The member '#memberName' can only be used within '#uri' or a template library."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
This warning is generated anywhere where a member annotated with
|
|
`@visibleForTemplate` is used outside of a "template" Dart file.
|
|
invalidUseOfVisibleForTestingMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String memberName: the name of the member
|
|
Uri uri: the uri of the file containing the defining class
|
|
problemMessage: "The member '#memberName' can only be used within '#uri' or a test."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where a member annotated with
|
|
`@visibleForTesting` is used outside the defining library, or a test.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member annotated with
|
|
`@visibleForTesting` is referenced anywhere other than the library in
|
|
which it is declared or in a library in the `test` directory.
|
|
|
|
#### Example
|
|
|
|
Given a file `c.dart` that contains the following:
|
|
|
|
```dart
|
|
%uri="lib/c.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@visibleForTesting
|
|
void m() {}
|
|
}
|
|
```
|
|
|
|
The following code, when not inside the `test` directory, produces this
|
|
diagnostic because the method `m` is marked as being visible only for
|
|
tests:
|
|
|
|
```dart
|
|
import 'c.dart';
|
|
|
|
void f(C c) {
|
|
c.[!m!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotated member should not be referenced outside of tests, then
|
|
remove the reference:
|
|
|
|
```dart
|
|
import 'c.dart';
|
|
|
|
void f(C c) {}
|
|
```
|
|
|
|
If it's OK to reference the annotated member outside of tests, then remove
|
|
the annotation:
|
|
|
|
```dart
|
|
class C {
|
|
void m() {}
|
|
}
|
|
```
|
|
invalidVisibilityAnnotation:
|
|
type: staticWarning
|
|
parameters:
|
|
String memberName: the name of the member
|
|
String annotationName: the name of the annotation
|
|
problemMessage: "The member '#memberName' is annotated with '#annotationName', but this annotation is only meaningful on declarations of public members."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where a private declaration is
|
|
annotated with `@visibleForTemplate` or `@visibleForTesting`.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either the `visibleForTemplate`
|
|
or [`visibleForTesting`][meta-visibleForTesting] annotation is applied to
|
|
a non-public declaration.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@[!visibleForTesting!]
|
|
void _someFunction() {}
|
|
|
|
void f() => _someFunction();
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the declaration doesn't need to be used by test code, then remove the
|
|
annotation:
|
|
|
|
```dart
|
|
void _someFunction() {}
|
|
|
|
void f() => _someFunction();
|
|
```
|
|
|
|
If it does, then make it public:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@visibleForTesting
|
|
void someFunction() {}
|
|
|
|
void f() => someFunction();
|
|
```
|
|
invalidVisibleForOverridingAnnotation:
|
|
type: staticWarning
|
|
removedIn: "3.11"
|
|
parameters: none
|
|
problemMessage: "The annotation 'visibleForOverriding' can only be applied to a public instance member that can be overridden."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when anything other than a public
|
|
instance member of a class is annotated with
|
|
[`visibleForOverriding`][meta-visibleForOverriding]. Because only public
|
|
instance members can be overridden outside the defining library, there's
|
|
no value to annotating any other declarations.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the annotation is on a
|
|
class, and classes can't be overridden:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@[!visibleForOverriding!]
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
invalidVisibleOutsideTemplateAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation 'visibleOutsideTemplate' can only be applied to a member of a class, enum, or mixin that is annotated with 'visibleForTemplate'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `@visibleOutsideTemplate`
|
|
annotation is used incorrectly. This annotation is only meant to annotate
|
|
members of a class, enum, or mixin that has the `@visibleForTemplate`
|
|
annotation, to opt those members out of the visibility restrictions that
|
|
`@visibleForTemplate` imposes.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because there is no
|
|
`@visibleForTemplate` annotation at the class level:
|
|
|
|
```dart
|
|
import 'package:angular_meta/angular_meta.dart';
|
|
|
|
class C {
|
|
@[!visibleOutsideTemplate!]
|
|
int m() {
|
|
return 1;
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the annotation is on
|
|
a class declaration, not a member of a class, enum, or mixin:
|
|
|
|
```dart
|
|
import 'package:angular_meta/angular_meta.dart';
|
|
|
|
@[!visibleOutsideTemplate!]
|
|
class C {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the class is only visible so that templates can reference it, then add
|
|
the `@visibleForTemplate` annotation to the class:
|
|
|
|
```dart
|
|
import 'package:angular_meta/angular_meta.dart';
|
|
|
|
@visibleForTemplate
|
|
class C {
|
|
@visibleOutsideTemplate
|
|
int m() {
|
|
return 1;
|
|
}
|
|
}
|
|
```
|
|
|
|
If the `@visibleOutsideTemplate` annotation is on anything other than a
|
|
member of a class, enum, or mixin with the `@visibleForTemplate`
|
|
annotation, remove the annotation:
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
returnTypeInvalidForCatchError:
|
|
type: staticWarning
|
|
parameters:
|
|
Type actualType: the return type of the function
|
|
Type expectedType: the expected return type as defined by the type of the Future
|
|
sharedName: invalidReturnTypeForCatchError
|
|
problemMessage: "The return type '#actualType' isn't assignable to '#expectedType', as required by 'Future.catchError'."
|
|
hasPublishedDocs: true
|
|
returnOfInvalidTypeFromCatchError:
|
|
type: staticWarning
|
|
parameters:
|
|
Type actualType: the return type as declared in the return statement
|
|
Type expectedType: the expected return type as defined by the type of the Future
|
|
sharedName: invalidReturnTypeForCatchError
|
|
problemMessage: "A value of type '#actualType' can't be returned by the 'onError' handler because it must be assignable to '#expectedType'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an invocation of
|
|
`Future.catchError` has an argument whose return type isn't compatible with
|
|
the type returned by the instance of `Future`. At runtime, the method
|
|
`catchError` attempts to return the value from the callback as the result
|
|
of the future, which results in another exception being thrown.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `future` is declared to
|
|
return an `int` while `callback` is declared to return a `String`, and
|
|
`String` isn't a subtype of `int`:
|
|
|
|
```dart
|
|
void f(Future<int> future, String Function(dynamic, StackTrace) callback) {
|
|
future.catchError([!callback!]);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the closure being
|
|
passed to `catchError` returns an `int` while `future` is declared to
|
|
return a `String`:
|
|
|
|
```dart
|
|
void f(Future<String> future) {
|
|
future.catchError((error, stackTrace) => [!3!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the instance of `Future` is declared correctly, then change the callback
|
|
to match:
|
|
|
|
```dart
|
|
void f(Future<int> future, int Function(dynamic, StackTrace) callback) {
|
|
future.catchError(callback);
|
|
}
|
|
```
|
|
|
|
If the declaration of the instance of `Future` is wrong, then change it to
|
|
match the callback:
|
|
|
|
```dart
|
|
void f(Future<String> future, String Function(dynamic, StackTrace) callback) {
|
|
future.catchError(callback);
|
|
}
|
|
```
|
|
returnOfInvalidTypeFromThen:
|
|
type: staticWarning
|
|
parameters:
|
|
Type actualType: the return type as declared in the return statement
|
|
Type expectedType: the expected return type as defined by the type of the Future
|
|
sharedName: invalidReturnTypeForThen
|
|
problemMessage: "A value of type '#actualType' can't be returned by the 'onError' handler because it must be assignable to '#expectedType', as required by 'Future.then'."
|
|
hasPublishedDocs: false
|
|
returnTypeInvalidForThen:
|
|
type: staticWarning
|
|
parameters:
|
|
Type actualType: the return type of the function
|
|
Type expectedType: the expected return type as defined by the type of the Future
|
|
sharedName: invalidReturnTypeForThen
|
|
problemMessage: "The return type '#actualType' isn't assignable to '#expectedType', as required by 'Future.then'."
|
|
hasPublishedDocs: false
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the return type of the
|
|
`onError` argument in `Future.then` is incompatible with the return type
|
|
of the `onValue` argument. At runtime, `Future.then` attempts to return
|
|
the value from the `onError` handler as the future's result, which
|
|
throws another exception.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the `onError` handler
|
|
returns a `String` instead of an `int`:
|
|
|
|
```dart
|
|
void f(Future<int> future) {
|
|
future.then((_) => 0, onError: (e, st) => [!'c'!]);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the return type of the
|
|
`onError` argument (`cb`) is incompatible with the return type of
|
|
`onValue`:
|
|
|
|
```dart
|
|
void f(Future<int> future, String Function(dynamic, StackTrace) cb) {
|
|
future.then<int>((_) => 1, onError: [!cb!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the `onValue` handler returns the correct type, then change the
|
|
`onError` handler to match:
|
|
|
|
```dart
|
|
void f(Future<int> future) {
|
|
future.then((_) => 0, onError: (e, st) => -1);
|
|
}
|
|
```
|
|
|
|
If the `onError` handler is correct, then change the `onValue` handler to
|
|
match:
|
|
|
|
```dart
|
|
void f(Future<String> future) {
|
|
future.then((_) => 'a', onError: (e, st) => 'c');
|
|
}
|
|
```
|
|
|
|
If both handlers are correct, then change the future type to match:
|
|
|
|
```dart
|
|
void f(Future<String> future) {
|
|
future.then<Object>((_) => 0, onError: (e, st) => 'c');
|
|
}
|
|
```
|
|
invalidReopenAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The annotation '@reopen' can only be applied to a class that opens capabilities that the supertype intentionally disallows."
|
|
correctionMessage: Try removing the '@reopen' annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where `@reopen` annotates a class which
|
|
did not reopen any type.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `@reopen` annotation has been
|
|
placed on a class or mixin that does not remove restrictions placed on the
|
|
superclass.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B` is
|
|
annotated with `@reopen` even though it doesn't expand the ability of `A`
|
|
to be subclassed:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
sealed class A {}
|
|
|
|
@[!reopen!]
|
|
class B extends A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the superclass should be restricted in a way that the subclass would
|
|
change, then modify the superclass to reflect those restrictions:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
interface class A {}
|
|
|
|
@reopen
|
|
class B extends A {}
|
|
```
|
|
|
|
If the superclass is correct, then remove the annotation:
|
|
|
|
```dart
|
|
sealed class A {}
|
|
|
|
class B extends A {}
|
|
```
|
|
invalidSealedAnnotation:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.5"
|
|
problemMessage: "The annotation '@sealed' can only be applied to classes."
|
|
correctionMessage: Try removing the '@sealed' annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where `@sealed` annotates something
|
|
other than a class.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a declaration other than a
|
|
class declaration has the `@sealed` annotation on it.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the `@sealed`
|
|
annotation is on a method declaration:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@[!sealed!]
|
|
void m() {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the annotation:
|
|
|
|
```dart
|
|
class A {
|
|
void m() {}
|
|
}
|
|
```
|
|
invalidWidgetPreviewApplication:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The '@Preview(...)' annotation can only be applied to public, statically accessible constructors and functions."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `@Preview(...)` annotation
|
|
is applied to an invalid widget preview target. Widget previews can only
|
|
be applied to public, statically accessible, explicitly defined
|
|
constructors and functions.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `_myPrivatePreview`
|
|
is private:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
// Invalid application to private top-level function.
|
|
@[!Preview!]()
|
|
// ignore: unused_element
|
|
Widget _myPrivatePreview() => Text('Foo');
|
|
```
|
|
|
|
The following code produces this diagnostic because `myExternalPreview`
|
|
is `external`:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
|
|
// Invalid application to an external function.
|
|
@[!Preview!]()
|
|
external Widget myExternalPreview();
|
|
```
|
|
|
|
The following code produces this diagnostic because `PublicWidget._()` is
|
|
private:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
class PublicWidget extends StatelessWidget {
|
|
// Invalid application to a private constructor.
|
|
@[!Preview!]()
|
|
PublicWidget._();
|
|
|
|
@override
|
|
Widget build(BuildContext) => Text('Foo');
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `instancePreview` is
|
|
an instance method:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
class PublicWidget extends StatelessWidget {
|
|
// Invalid application to a instance member.
|
|
@[!Preview!]()
|
|
Widget instancePreview() => PublicWidget();
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Text('Foo');
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `_PrivateWidget` is
|
|
private:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
// ignore: unused_element
|
|
class _PrivateWidget extends StatelessWidget {
|
|
// Invalid application to a constructor of a private class.
|
|
@[!Preview!]()
|
|
_PrivateWidget();
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Text('Foo');
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `_PrivateWidget` is
|
|
private:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
// ignore: unused_element
|
|
class _PrivateWidget extends StatelessWidget {
|
|
// Invalid application to a static method of a private class.
|
|
@[!Preview!]()
|
|
Widget privateStatic() => _PrivateWidget();
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Text('Foo');
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `AbstractWidget` is
|
|
an `abstract` class:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
abstract class AbstractWidget extends StatelessWidget {
|
|
// Invalid application to a constructor of an abstract class.
|
|
@[!Preview!]()
|
|
AbstractWidget();
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Text('Foo');
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Create a dedicated public, statically accessible, and explicitly defined
|
|
constructor, top-level function, or class member for use as a preview:
|
|
|
|
invalidWidgetPreviewPrivateArgument:
|
|
type: staticWarning
|
|
parameters:
|
|
String privateSymbolName: the name of the private symbol
|
|
String suggestedName: the name of the proposed public symbol equivalent
|
|
problemMessage: "'@Preview(...)' can only accept arguments that consist of literals and public symbols."
|
|
correctionMessage: "Rename private symbol '#privateSymbolName' to '#suggestedName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the `Preview` constructor is
|
|
invoked with arguments that contain references to private symbols.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the constant variable
|
|
`_name` is private to the current library:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
const String _name = 'My Foo Preview';
|
|
|
|
@Preview([!name: _name!])
|
|
Widget myPreview() => Text('Foo');
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If appropriate, the private symbol should be made public:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
const String name = 'My Foo Preview';
|
|
|
|
@Preview(name: name)
|
|
Widget myPreview() => Text('Foo');
|
|
```
|
|
|
|
Otherwise, a different public constant symbol should be used:
|
|
|
|
```dart
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter/widget_previews.dart';
|
|
|
|
@Preview(name: 'My Foo Preview')
|
|
Widget myPreview() => Text('Foo');
|
|
```
|
|
missingOverrideOfMustBeOverriddenOne:
|
|
type: staticWarning
|
|
parameters:
|
|
String member: the name of the member
|
|
sharedName: missingOverrideOfMustBeOverridden
|
|
problemMessage: "Missing a required override of '#member'."
|
|
correctionMessage: Try overriding the missing member.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an instance member that has the
|
|
`@mustBeOverridden` annotation isn't overridden in a subclass.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the class `B` doesn't
|
|
have an override of the inherited method `A.m` when `A.m` is annotated
|
|
with `@mustBeOverridden`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@mustBeOverridden
|
|
void m() {}
|
|
}
|
|
|
|
class [!B!] extends A {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotation is appropriate for the member, then override the member
|
|
in the subclass:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@mustBeOverridden
|
|
void m() {}
|
|
}
|
|
|
|
class B extends A {
|
|
@override
|
|
void m() {}
|
|
}
|
|
```
|
|
|
|
If the annotation isn't appropriate for the member, then remove the
|
|
annotation:
|
|
|
|
```dart
|
|
class A {
|
|
void m() {}
|
|
}
|
|
|
|
class B extends A {}
|
|
```
|
|
missingOverrideOfMustBeOverriddenTwo:
|
|
type: staticWarning
|
|
parameters:
|
|
String firstMember: the name of the first member
|
|
String secondMember: the name of the second member
|
|
sharedName: missingOverrideOfMustBeOverridden
|
|
problemMessage: "Missing a required override of '#firstMember' and '#secondMember'."
|
|
correctionMessage: Try overriding the missing members.
|
|
hasPublishedDocs: true
|
|
missingOverrideOfMustBeOverriddenThreePlus:
|
|
type: staticWarning
|
|
parameters:
|
|
String firstMember: the name of the first member
|
|
String secondMember: the name of the second member
|
|
int additionalCount: the number of additional missing members that aren't listed
|
|
sharedName: missingOverrideOfMustBeOverridden
|
|
problemMessage: "Missing a required override of '#firstMember', '#secondMember', and #additionalCount more."
|
|
correctionMessage: Try overriding the missing members.
|
|
hasPublishedDocs: true
|
|
missingRequiredParam:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the parameter
|
|
problemMessage: "The parameter '#name' is required."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Generates a warning for a constructor, function or method invocation where
|
|
a required parameter is missing.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method or function with a
|
|
named parameter that is annotated as being required is invoked without
|
|
providing a value for the parameter.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the named parameter `x`
|
|
is required:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
// ignore: deprecated_member_use
|
|
void f({@required int? x}) {}
|
|
|
|
void g() {
|
|
[!f!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Provide the required value:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
// ignore: deprecated_member_use
|
|
void f({@required int? x}) {}
|
|
|
|
void g() {
|
|
f(x: 2);
|
|
}
|
|
```
|
|
missingRequiredParamWithDetails:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the parameter
|
|
String details: message details
|
|
sharedName: missingRequiredParam
|
|
problemMessage: "The parameter '#name' is required. #details."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Generates a warning for a constructor, function or method invocation where
|
|
a required parameter is missing.
|
|
missingReturn:
|
|
type: staticWarning
|
|
parameters:
|
|
String p0: the name of the declared return type
|
|
removedIn: "3.0"
|
|
problemMessage: "This function has a return type of '#p0', but doesn't end with a return statement."
|
|
correctionMessage: "Try adding a return statement, or changing the return type to 'void'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
Any function or method that doesn't end with either an explicit return or a
|
|
throw implicitly returns `null`. This is rarely the desired behavior. The
|
|
analyzer produces this diagnostic when it finds an implicit return.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `f` doesn't end with a
|
|
return:
|
|
|
|
```dart
|
|
%language=2.9
|
|
int [!f!](int x) {
|
|
if (x < 0) {
|
|
return 0;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add a `return` statement that makes the return value explicit, even if
|
|
`null` is the appropriate value.
|
|
mixinOnSealedClass:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the sealed class
|
|
problemMessage: "The class '#name' shouldn't be used as a mixin constraint because it is sealed, and any class mixing in this mixin must have '#name' as a superclass."
|
|
correctionMessage: Try composing with this class, or refer to its documentation for more information.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
This warning is generated anywhere where a `@sealed` class is used as a
|
|
a superclass constraint of a mixin.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the superclass constraint of a
|
|
mixin is a class from a different package that was marked as
|
|
[`sealed`][meta-sealed]. Classes that are sealed can't be extended,
|
|
implemented, mixed in, or used as a superclass constraint.
|
|
|
|
#### Example
|
|
|
|
If the package `p` defines a sealed class:
|
|
|
|
```dart
|
|
%uri="package:p/p.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
@sealed
|
|
class C {}
|
|
```
|
|
|
|
Then, the following code, when in a package other than `p`, produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
import 'package:p/p.dart';
|
|
|
|
[!mixin M on C {}!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the classes that use the mixin don't need to be subclasses of the sealed
|
|
class, then consider adding a field and delegating to the wrapped instance
|
|
of the sealed class.
|
|
mustBeImmutable:
|
|
type: staticWarning
|
|
parameters:
|
|
String fieldNames: the names of the non-final field names, joined with commas
|
|
problemMessage: "This class (or a class that this class inherits from) is marked as '@immutable', but one or more of its instance fields aren't final: #fieldNames"
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Generates a warning for classes that inherit from classes annotated with
|
|
`@immutable` but that are not immutable.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an immutable class defines one
|
|
or more instance fields that aren't final. A class is immutable if it's
|
|
marked as being immutable using the annotation
|
|
[`immutable`][meta-immutable] or if it's a subclass of an immutable class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field `x` isn't
|
|
final:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@immutable
|
|
class [!C!] {
|
|
int x;
|
|
|
|
C(this.x);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If instances of the class should be immutable, then add the keyword `final`
|
|
to all non-final field declarations:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@immutable
|
|
class C {
|
|
final int x;
|
|
|
|
C(this.x);
|
|
}
|
|
```
|
|
|
|
If the instances of the class should be mutable, then remove the
|
|
annotation, or choose a different superclass if the annotation is
|
|
inherited:
|
|
|
|
```dart
|
|
class C {
|
|
int x;
|
|
|
|
C(this.x);
|
|
}
|
|
```
|
|
mustCallSuper:
|
|
type: staticWarning
|
|
parameters:
|
|
String className: the name of the class declaring the overridden method
|
|
problemMessage: "This method overrides a method annotated as '@mustCallSuper' in '#className', but doesn't invoke the overridden method."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a method that overrides a method
|
|
that is annotated as [`mustCallSuper`][meta-mustCallSuper] doesn't invoke
|
|
the overridden method as required.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the method `m` in `B`
|
|
doesn't invoke the overridden method `m` in `A`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@mustCallSuper
|
|
m() {}
|
|
}
|
|
|
|
class B extends A {
|
|
@override
|
|
[!m!]() {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add an invocation of the overridden method in the overriding method:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {
|
|
@mustCallSuper
|
|
m() {}
|
|
}
|
|
|
|
class B extends A {
|
|
@override
|
|
m() {
|
|
super.m();
|
|
}
|
|
}
|
|
```
|
|
nonConstArgumentForConstParameter:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the argument
|
|
problemMessage: "Argument '#name' must be a constant."
|
|
correctionMessage: Try replacing the argument with a constant.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a parameter is
|
|
annotated with the [`mustBeConst`][meta-mustBeConst] annotation and
|
|
the corresponding argument is not a constant expression.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic on the invocation of
|
|
the function `f` because the value of the argument passed to the
|
|
function `g` isn't a constant:
|
|
|
|
```dart
|
|
%ignore=experimental_member_use
|
|
import 'package:meta/meta.dart' show mustBeConst;
|
|
|
|
int f(int value) => g([!value!]);
|
|
|
|
int g(@mustBeConst int value) => value + 1;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a suitable constant is available to use, then replace the argument
|
|
with a constant:
|
|
|
|
```dart
|
|
%ignore=experimental_member_use
|
|
import 'package:meta/meta.dart' show mustBeConst;
|
|
|
|
const v = 3;
|
|
|
|
int f() => g(v);
|
|
|
|
int g(@mustBeConst int value) => value + 1;
|
|
```
|
|
tearoffWithMustBeConstParameter:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the function
|
|
problemMessage: "The function '#name' has a parameter marked as '@mustBeConst' and can't be torn off."
|
|
correctionMessage: Try calling the function directly with a constant argument.
|
|
hasPublishedDocs: false
|
|
nonConstCallToLiteralConstructorUsingNew:
|
|
type: staticWarning
|
|
parameters:
|
|
String constructorName: the name of the annotated constructor
|
|
sharedName: nonConstCallToLiteralConstructor
|
|
problemMessage: "This instance creation must be 'const', because the #constructorName constructor is marked as '@literal'."
|
|
correctionMessage: "Try replacing the 'new' keyword with 'const'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Generate a warning for non-const instance creation (with the `new` keyword)
|
|
using a constructor annotated with `@literal`.
|
|
nonConstCallToLiteralConstructor:
|
|
type: staticWarning
|
|
parameters:
|
|
String constructorName: the name of the annotated constructor
|
|
problemMessage: "This instance creation must be 'const', because the #constructorName constructor is marked as '@literal'."
|
|
correctionMessage: "Try adding a 'const' keyword."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
Generates a warning for non-const instance creation using a constructor
|
|
annotated with `@literal`.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor that has the
|
|
[`literal`][meta-literal] annotation is invoked without using the `const`
|
|
keyword, but all of the arguments to the constructor are constants. The
|
|
annotation indicates that the constructor should be used to create a
|
|
constant value whenever possible.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@literal
|
|
const C();
|
|
}
|
|
|
|
C f() => [!C()!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Add the keyword `const` before the constructor invocation:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@literal
|
|
const C();
|
|
}
|
|
|
|
void f() => const C();
|
|
```
|
|
nonNullableEqualsParameter:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The parameter type of '==' operators should be non-nullable."
|
|
correctionMessage: Try using a non-nullable type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an override of the operator
|
|
`==` has a parameter whose type is nullable. The language spec makes it
|
|
impossible for the argument of the method to be `null`, and the
|
|
parameter's type should reflect that.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the implementation of
|
|
the operator `==` in `C` :
|
|
|
|
```dart
|
|
class C {
|
|
@override
|
|
bool operator [!==!](Object? other) => false;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Make the parameter type be non-nullable:
|
|
|
|
```dart
|
|
class C {
|
|
@override
|
|
bool operator ==(Object other) => false;
|
|
}
|
|
```
|
|
nullableTypeInCatchClause:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression."
|
|
correctionMessage: Try using a non-nullable type.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the type following `on` in a
|
|
`catch` clause is a nullable type. It isn't valid to specify a nullable
|
|
type because it isn't possible to catch `null` (because it's a runtime
|
|
error to throw `null`).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the exception type is
|
|
specified to allow `null` when `null` can't be thrown:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} on [!FormatException?!] {
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the question mark from the type:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} on FormatException {
|
|
}
|
|
}
|
|
```
|
|
nullArgumentToNonNullType:
|
|
type: staticWarning
|
|
parameters:
|
|
String memberName: the name of the member being invoked
|
|
String typeArgumentName: the type argument associated with the method
|
|
problemMessage: "'#memberName' shouldn't be called with a 'null' argument for the non-nullable type argument '#typeArgumentName'."
|
|
correctionMessage: Try adding a non-null argument.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when `null` is passed to either the
|
|
constructor `Future.value` or the method `Completer.complete` when the type
|
|
argument used to create the instance was non-nullable. Even though the type
|
|
system can't express this restriction, passing in a `null` results in a
|
|
runtime exception.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `null` is being passed
|
|
to the constructor `Future.value` even though the type argument is the
|
|
non-nullable type `String`:
|
|
|
|
```dart
|
|
Future<String> f() {
|
|
return Future.value([!null!]);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Pass in a non-null value:
|
|
|
|
```dart
|
|
Future<String> f() {
|
|
return Future.value('');
|
|
}
|
|
```
|
|
nullCheckAlwaysFails:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "This null-check will always throw an exception because the expression will always evaluate to 'null'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the null check operator (`!`)
|
|
is used on an expression whose value can only be `null`. In such a case
|
|
the operator always throws an exception, which likely isn't the intended
|
|
behavior.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `g` will
|
|
always return `null`, which means that the null check in `f` will always
|
|
throw:
|
|
|
|
```dart
|
|
void f() {
|
|
[!g()!!];
|
|
}
|
|
|
|
Null g() => null;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intend to always throw an exception, then replace the null check
|
|
with an explicit `throw` expression to make the intent more clear:
|
|
|
|
```dart
|
|
void f() {
|
|
g();
|
|
throw TypeError();
|
|
}
|
|
|
|
Null g() => null;
|
|
```
|
|
overrideOnNonOverridingField:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: overrideOnNonOverridingMember
|
|
problemMessage: "The field doesn't override an inherited getter or setter."
|
|
correctionMessage: Try updating this class to match the superclass, or removing the override annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
A field with the override annotation does not override a getter or setter.
|
|
overrideOnNonOverridingGetter:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: overrideOnNonOverridingMember
|
|
problemMessage: "The getter doesn't override an inherited getter."
|
|
correctionMessage: Try updating this class to match the superclass, or removing the override annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
A getter with the override annotation does not override an existing getter.
|
|
overrideOnNonOverridingMethod:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: overrideOnNonOverridingMember
|
|
problemMessage: "The method doesn't override an inherited method."
|
|
correctionMessage: Try updating this class to match the superclass, or removing the override annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
A method with the override annotation does not override an existing method.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a class member is annotated with
|
|
the `@override` annotation, but the member isn't declared in any of the
|
|
supertypes of the class.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `m` isn't declared in
|
|
any of the supertypes of `C`:
|
|
|
|
```dart
|
|
class C {
|
|
@override
|
|
String [!m!]() => '';
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the member is intended to override a member with a different name, then
|
|
update the member to have the same name:
|
|
|
|
```dart
|
|
class C {
|
|
@override
|
|
String toString() => '';
|
|
}
|
|
```
|
|
|
|
If the member is intended to override a member that was removed from the
|
|
superclass, then consider removing the member from the subclass.
|
|
|
|
If the member can't be removed, then remove the annotation.
|
|
overrideOnNonOverridingSetter:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: overrideOnNonOverridingMember
|
|
problemMessage: "The setter doesn't override an inherited setter."
|
|
correctionMessage: Try updating this class to match the superclass, or removing the override annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
A setter with the override annotation does not override an existing setter.
|
|
patternNeverMatchesValueType:
|
|
type: staticWarning
|
|
parameters:
|
|
Type matchedValueType: the matched value type
|
|
Type requiredType: the required pattern type
|
|
problemMessage: "The matched value type '#matchedValueType' can never match the required type '#requiredType'."
|
|
correctionMessage: "Try using a different pattern."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the object's type can't be
|
|
matched by the pattern.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because a `double` is matched
|
|
by an `int` pattern, which can never succeed:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if (s case [!int!] _) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If one of the types is wrong, then change one or both so the pattern match
|
|
can succeed:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if (s case String _) {}
|
|
}
|
|
```
|
|
|
|
If the types are correct, then remove the pattern match:
|
|
|
|
```dart
|
|
void f(double x) {}
|
|
```
|
|
receiverOfTypeNever:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The receiver is of type 'Never', and will never complete with a value."
|
|
correctionMessage: Try checking for throw expressions or type errors in the receiver
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
It is not an error to call or tear-off a method, setter, or getter, or to
|
|
read or write a field, on a receiver of static type `Never`.
|
|
Implementations that provide feedback about dead or unreachable code are
|
|
encouraged to indicate that any arguments to the invocation are
|
|
unreachable.
|
|
|
|
It is not an error to apply an expression of type `Never` in the function
|
|
position of a function call. Implementations that provide feedback about
|
|
dead or unreachable code are encouraged to indicate that any arguments to
|
|
the call are unreachable.
|
|
redeclareOnNonRedeclaringMember:
|
|
type: staticWarning
|
|
parameters:
|
|
String kind: the kind of member
|
|
problemMessage: "The #kind doesn't redeclare a #kind declared in a superinterface."
|
|
correctionMessage: Try updating this member to match a declaration in a superinterface, or removing the redeclare annotation.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating the use of a redeclare annotation on a member that does not redeclare.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a member of an extension type
|
|
is annotated with `@redeclare`, but none of the implemented interfaces
|
|
has a member with the same name.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the member `n`
|
|
declared by the extension type `E` is annotated with `@redeclare`, but `C`
|
|
doesn't have a member named `n`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
void m() {}
|
|
}
|
|
|
|
extension type E(C c) implements C {
|
|
@redeclare
|
|
void [!n!]() {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the annotated member has the right name, then remove the annotation:
|
|
|
|
```dart
|
|
class C {
|
|
void m() {}
|
|
}
|
|
|
|
extension type E(C c) implements C {
|
|
void n() {}
|
|
}
|
|
```
|
|
|
|
If the annotated member is suppose to replace a member from the
|
|
implemented interfaces, then change the name of the annotated member to
|
|
match the member being replaced:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
void m() {}
|
|
}
|
|
|
|
extension type E(C c) implements C {
|
|
@redeclare
|
|
void m() {}
|
|
}
|
|
```
|
|
removedLintUse:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String since: the SDK version in which the lint was removed
|
|
problemMessage: "'#ruleName' was removed in Dart '#since'"
|
|
correctionMessage: "Remove the reference to '#ruleName'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
An error code indicating use of a removed lint rule.
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a lint that has been removed is
|
|
used in an analysis options file. Because the lint no longer exists,
|
|
referencing it will have no effect.
|
|
|
|
#### Example
|
|
|
|
Assuming that the lint `removed_lint` has been removed, the following
|
|
options file produces this diagnostic:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- always_put_required_named_parameters_first
|
|
- [!removed_lint!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the reference to the lint code:
|
|
|
|
```yaml
|
|
%uri="analysis_options.yaml"
|
|
linter:
|
|
rules:
|
|
- always_put_required_named_parameters_first
|
|
```
|
|
replacedLintUse:
|
|
type: staticWarning
|
|
parameters:
|
|
String ruleName: the rule name
|
|
String since: the SDK version in which the lint was removed
|
|
String replacement: the name of a replacing lint
|
|
problemMessage: "'#ruleName' was replaced by '#replacement' in Dart '#since'."
|
|
correctionMessage: "Replace '#ruleName' with '#replacement'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
An error code indicating use of a removed lint rule.
|
|
returnOfDoNotStore:
|
|
type: staticWarning
|
|
parameters:
|
|
String invokedFunction: the name of the annotated function being invoked
|
|
String returningFunction: the name of the function containing the return
|
|
problemMessage: "'#invokedFunction' is annotated with 'doNotStore' and shouldn't be returned unless '#returningFunction' is also annotated."
|
|
correctionMessage: "Annotate '#returningFunction' with 'doNotStore'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a value that is annotated with
|
|
the [`doNotStore`][meta-doNotStore] annotation is returned from a method,
|
|
getter, or function that doesn't have the same annotation.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the result of invoking
|
|
`f` shouldn't be stored, but the function `g` isn't annotated to preserve
|
|
that semantic:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@doNotStore
|
|
int f() => 0;
|
|
|
|
int g() => [!f()!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the value that shouldn't be stored is the correct value to return, then
|
|
mark the function with the [`doNotStore`][meta-doNotStore] annotation:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@doNotStore
|
|
int f() => 0;
|
|
|
|
@doNotStore
|
|
int g() => f();
|
|
```
|
|
|
|
Otherwise, return a different value from the function:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@doNotStore
|
|
int f() => 0;
|
|
|
|
int g() => 0;
|
|
```
|
|
sdkVersionAsyncExportedFromCore:
|
|
type: staticWarning
|
|
parameters:
|
|
String p0: the name of the class
|
|
removedIn: "3.2"
|
|
problemMessage: "The class '#p0' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: "Try either importing 'dart:async' or updating the SDK constraints."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either the class `Future` or
|
|
`Stream` is referenced in a library that doesn't import `dart:async` in
|
|
code that has an SDK constraint whose lower bound is less than 2.1.0. In
|
|
earlier versions, these classes weren't defined in `dart:core`, so the
|
|
import was necessary.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.1.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.0.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
void f([!Future!] f) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the classes to be referenced:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.1.0 <2.4.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then import the
|
|
`dart:async` library.
|
|
|
|
```dart
|
|
import 'dart:async';
|
|
|
|
void f(Future f) {}
|
|
```
|
|
sdkVersionAsExpressionInConstContext:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "The use of an as expression in a constant expression wasn't supported until version 2.3.2, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `as` expression inside a
|
|
[constant context][] is found in code that has an SDK constraint whose
|
|
lower bound is less than 2.3.2. Using an `as` expression in a
|
|
[constant context][] wasn't supported in earlier versions, so this code
|
|
won't be able to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.3.2:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.1.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces
|
|
this diagnostic:
|
|
|
|
```dart
|
|
const num n = 3;
|
|
const int i = [!n as int!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the expression to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.3.2 <2.4.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then either rewrite the
|
|
code to not use an `as` expression, or change the code so that the `as`
|
|
expression isn't in a [constant context][]:
|
|
|
|
```dart
|
|
num x = 3;
|
|
int y = x as int;
|
|
```
|
|
sdkVersionBoolOperatorInConstContext:
|
|
type: staticWarning
|
|
parameters:
|
|
String p0: the name of the operator
|
|
removedIn: "3.2"
|
|
problemMessage: "The use of the operator '#p0' for 'bool' operands in a constant context wasn't supported until version 2.3.2, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when any use of the `&`, `|`, or `^`
|
|
operators on the class `bool` inside a [constant context][] is found in
|
|
code that has an SDK constraint whose lower bound is less than 2.3.2. Using
|
|
these operators in a [constant context][] wasn't supported in earlier
|
|
versions, so this code won't be able to run against earlier versions of the
|
|
SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.3.2:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.1.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
const bool a = true;
|
|
const bool b = false;
|
|
const bool c = a [!&!] b;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the operators to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.3.2 <2.4.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then either rewrite the
|
|
code to not use these operators, or change the code so that the expression
|
|
isn't in a [constant context][]:
|
|
|
|
```dart
|
|
const bool a = true;
|
|
const bool b = false;
|
|
bool c = a & b;
|
|
```
|
|
sdkVersionConstructorTearoffs:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Tearing off a constructor requires the 'constructor-tearoffs' language feature."
|
|
correctionMessage: "Try updating your 'pubspec.yaml' to set the minimum SDK constraint to 2.15 or higher, and running 'pub get'."
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
There is also a [diag.experimentNotEnabled] code which
|
|
catches some cases of constructor tearoff features (like
|
|
`List<int>.filled;`). Other constructor tearoff cases are not realized
|
|
until resolution (like `List.filled;`).
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a constructor tear-off is found
|
|
in code that has an SDK constraint whose lower bound is less than 2.15.
|
|
Constructor tear-offs weren't supported in earlier versions, so this code
|
|
won't be able to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.15:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.9.0 <2.15.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
%language=2.14
|
|
var setConstructor = [!Set.identity!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the operator to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.15.0 <2.16.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then rewrite the code to
|
|
not use constructor tear-offs:
|
|
|
|
```dart
|
|
%language=2.14
|
|
var setConstructor = () => Set.identity();
|
|
```
|
|
sdkVersionEqEqOperatorInConstContext:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "Using the operator '==' for non-primitive types wasn't supported until version 2.3.2, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the operator `==` is used on a
|
|
non-primitive type inside a [constant context][] is found in code that has
|
|
an SDK constraint whose lower bound is less than 2.3.2. Using this operator
|
|
in a [constant context][] wasn't supported in earlier versions, so this
|
|
code won't be able to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.3.2:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.1.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
%language=2.9
|
|
class C {}
|
|
const C a = null;
|
|
const C b = null;
|
|
const bool same = a [!==!] b;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the operator to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.3.2 <2.4.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then either rewrite the
|
|
code to not use the `==` operator, or change the code so that the
|
|
expression isn't in a [constant context][]:
|
|
|
|
```dart
|
|
%language=2.9
|
|
class C {}
|
|
const C a = null;
|
|
const C b = null;
|
|
bool same = a == b;
|
|
```
|
|
sdkVersionExtensionMethods:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "Extension methods weren't supported until version 2.6.0, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an extension declaration or an
|
|
extension override is found in code that has an SDK constraint whose lower
|
|
bound is less than 2.6.0. Using extensions wasn't supported in earlier
|
|
versions, so this code won't be able to run against earlier versions of the
|
|
SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.6.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.4.0 <2.7.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces
|
|
this diagnostic:
|
|
|
|
```dart
|
|
[!extension!] E on String {
|
|
void sayHello() {
|
|
print('Hello $this');
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the syntax to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.6.0 <2.7.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then rewrite the code to
|
|
not make use of extensions. The most common way to do this is to rewrite
|
|
the members of the extension as top-level functions (or methods) that take
|
|
the value that would have been bound to `this` as a parameter:
|
|
|
|
```dart
|
|
void sayHello(String s) {
|
|
print('Hello $s');
|
|
}
|
|
```
|
|
sdkVersionGtGtGtOperator:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "The operator '>>>' wasn't supported until version 2.14.0, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the operator `>>>` is used in
|
|
code that has an SDK constraint whose lower bound is less than 2.14.0. This
|
|
operator wasn't supported in earlier versions, so this code won't be able
|
|
to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.14.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.0.0 <2.15.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
int x = 3 [!>>>!] 4;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the operator to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.14.0 <2.15.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then rewrite the code to
|
|
not use the `>>>` operator:
|
|
|
|
```dart
|
|
int x = logicalShiftRight(3, 4);
|
|
|
|
int logicalShiftRight(int leftOperand, int rightOperand) {
|
|
int divisor = 1 << rightOperand;
|
|
if (divisor == 0) {
|
|
return 0;
|
|
}
|
|
return leftOperand ~/ divisor;
|
|
}
|
|
```
|
|
sdkVersionIsExpressionInConstContext:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "The use of an is expression in a constant context wasn't supported until version 2.3.2, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an `is` expression inside a
|
|
[constant context][] is found in code that has an SDK constraint whose
|
|
lower bound is less than 2.3.2. Using an `is` expression in a
|
|
[constant context][] wasn't supported in earlier versions, so this code
|
|
won't be able to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.3.2:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.1.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces
|
|
this diagnostic:
|
|
|
|
```dart
|
|
const Object x = 4;
|
|
const y = [!x is int!] ? 0 : 1;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the expression to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.3.2 <2.4.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then either rewrite the
|
|
code to not use the `is` operator, or, if that isn't possible, change the
|
|
code so that the `is` expression isn't in a
|
|
[constant context][]:
|
|
|
|
```dart
|
|
const Object x = 4;
|
|
var y = x is int ? 0 : 1;
|
|
```
|
|
sdkVersionNever:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.0"
|
|
problemMessage: "The type 'Never' wasn't supported until version 2.12.0, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a reference to the class `Never`
|
|
is found in code that has an SDK constraint whose lower bound is less than
|
|
2.12.0. This class wasn't defined in earlier versions, so this code won't
|
|
be able to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.12.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.5.0 <2.6.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
%language=2.9
|
|
[!Never!] n;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the type to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.12.0 <2.13.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then rewrite the code to
|
|
not reference this class:
|
|
|
|
```dart
|
|
dynamic x;
|
|
```
|
|
sdkVersionSetLiteral:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "Set literals weren't supported until version 2.2, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a set literal is found in code
|
|
that has an SDK constraint whose lower bound is less than 2.2.0. Set
|
|
literals weren't supported in earlier versions, so this code won't be able
|
|
to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.2.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.1.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
var s = [!<int>{}!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the syntax to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.2.0 <2.4.0'
|
|
```
|
|
|
|
If you do need to support older versions of the SDK, then replace the set
|
|
literal with code that creates the set without the use of a literal:
|
|
|
|
```dart
|
|
var s = new Set<int>();
|
|
```
|
|
sdkVersionSince:
|
|
type: staticWarning
|
|
parameters:
|
|
String availableVersion: the version specified in the `@Since()` annotation
|
|
String versionConstraints: the SDK version constraints
|
|
problemMessage: "This API is available since SDK #availableVersion, but constraints '#versionConstraints' don't guarantee it."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: false
|
|
sdkVersionUiAsCode:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "The for, if, and spread elements weren't supported until version 2.3.0, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a for, if, or spread element is
|
|
found in code that has an SDK constraint whose lower bound is less than
|
|
2.3.0. Using a for, if, or spread element wasn't supported in earlier
|
|
versions, so this code won't be able to run against earlier versions of the
|
|
SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.3.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.2.0 <2.4.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces
|
|
this diagnostic:
|
|
|
|
```dart
|
|
var digits = [[!for (int i = 0; i < 10; i++) i!]];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the syntax to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.3.0 <2.4.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then rewrite the code to
|
|
not make use of those elements:
|
|
|
|
```dart
|
|
var digits = _initializeDigits();
|
|
|
|
List<int> _initializeDigits() {
|
|
var digits = <int>[];
|
|
for (int i = 0; i < 10; i++) {
|
|
digits.add(i);
|
|
}
|
|
return digits;
|
|
}
|
|
```
|
|
sdkVersionUiAsCodeInConstContext:
|
|
type: staticWarning
|
|
parameters: none
|
|
removedIn: "3.2"
|
|
problemMessage: "The if and spread elements weren't supported in constant expressions until version 2.5.0, but this code is required to be able to run on earlier versions."
|
|
correctionMessage: Try updating the SDK constraints.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an if or spread element inside
|
|
a [constant context][] is found in code that has an SDK constraint whose
|
|
lower bound is less than 2.5.0. Using an if or spread element inside a
|
|
[constant context][] wasn't supported in earlier versions, so this code
|
|
won't be able to run against earlier versions of the SDK.
|
|
|
|
#### Example
|
|
|
|
Here's an example of a pubspec that defines an SDK constraint with a lower
|
|
bound of less than 2.5.0:
|
|
|
|
```yaml
|
|
%uri="pubspec.yaml"
|
|
environment:
|
|
sdk: '>=2.4.0 <2.6.0'
|
|
```
|
|
|
|
In the package that has that pubspec, code like the following produces
|
|
this diagnostic:
|
|
|
|
```dart
|
|
const a = [1, 2];
|
|
const b = [[!...a!]];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you don't need to support older versions of the SDK, then you can
|
|
increase the SDK constraint to allow the syntax to be used:
|
|
|
|
```yaml
|
|
environment:
|
|
sdk: '>=2.5.0 <2.6.0'
|
|
```
|
|
|
|
If you need to support older versions of the SDK, then rewrite the code to
|
|
not make use of those elements:
|
|
|
|
```dart
|
|
const a = [1, 2];
|
|
const b = [1, 2];
|
|
```
|
|
|
|
If that isn't possible, change the code so that the element isn't in a
|
|
[constant context][]:
|
|
|
|
```dart
|
|
const a = [1, 2];
|
|
var b = [...a];
|
|
```
|
|
strictRawType:
|
|
type: staticWarning
|
|
parameters:
|
|
Type type: the name of the generic type
|
|
problemMessage: "The generic type '#type' should have explicit type arguments but doesn't."
|
|
correctionMessage: "Use explicit type arguments for '#type'."
|
|
hasPublishedDocs: false
|
|
comment: |-
|
|
When "strict-raw-types" is enabled, "raw types" must have type arguments.
|
|
|
|
A "raw type" is a type name that does not use inference to fill in missing
|
|
type arguments; instead, each type argument is instantiated to its bound.
|
|
subtypeOfSealedClass:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the sealed class
|
|
problemMessage: "The class '#name' shouldn't be extended, mixed in, or implemented because it's sealed."
|
|
correctionMessage: "Try composing instead of inheriting, or refer to the documentation of '#name' for more information."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a sealed class (one that either
|
|
has the [`sealed`][meta-sealed] annotation or inherits or mixes in a
|
|
sealed class) is referenced in either the `extends`, `implements`, or
|
|
`with` clause of a class or mixin declaration if the declaration isn't in
|
|
the same package as the sealed class.
|
|
|
|
#### Example
|
|
|
|
Given a library in a package other than the package being analyzed that
|
|
contains the following:
|
|
|
|
```dart
|
|
%uri="package:a/a.dart"
|
|
import 'package:meta/meta.dart';
|
|
|
|
class A {}
|
|
|
|
@sealed
|
|
class B {}
|
|
```
|
|
|
|
The following code produces this diagnostic because `C`, which isn't in the
|
|
same package as `B`, is extending the sealed class `B`:
|
|
|
|
```dart
|
|
import 'package:a/a.dart';
|
|
|
|
[!class C extends B {}!]
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the class doesn't need to be a subtype of the sealed class, then change
|
|
the declaration so that it isn't:
|
|
|
|
```dart
|
|
import 'package:a/a.dart';
|
|
|
|
class B extends A {}
|
|
```
|
|
|
|
If the class needs to be a subtype of the sealed class, then either change
|
|
the sealed class so that it's no longer sealed or move the subclass into
|
|
the same package as the sealed class.
|
|
textDirectionCodePointInComment:
|
|
type: staticWarning
|
|
parameters:
|
|
String codePoint: the unicode sequence of the code point.
|
|
problemMessage: The Unicode code point 'U+#codePoint' changes the appearance of text from how it's interpreted by the compiler.
|
|
correctionMessage: Try removing the code point or using the Unicode escape sequence '\u#codePoint'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters source that
|
|
contains text direction Unicode code points. These code points cause
|
|
source code in either a string literal or a comment to be interpreted
|
|
and compiled differently than how it appears in editors, leading to
|
|
possible security vulnerabilities.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic twice because there are
|
|
hidden characters at the start and end of the label string:
|
|
|
|
```dart
|
|
var label = '[!I!]nteractive text[!'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the code points are intended to be included in the string literal,
|
|
then escape them:
|
|
|
|
```dart
|
|
var label = '\u202AInteractive text\u202C';
|
|
```
|
|
|
|
If the code points aren't intended to be included in the string literal,
|
|
then remove them:
|
|
|
|
```dart
|
|
var label = 'Interactive text';
|
|
```
|
|
textDirectionCodePointInLiteral:
|
|
type: staticWarning
|
|
parameters:
|
|
String codePoint: the unicode sequence of the code point.
|
|
problemMessage: The Unicode code point 'U+#codePoint' changes the appearance of text from how it's interpreted by the compiler.
|
|
correctionMessage: Try removing the code point or using the Unicode escape sequence '\u#codePoint'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it encounters source that
|
|
contains text direction Unicode code points. These code points cause
|
|
source code in either a string literal or a comment to be interpreted
|
|
and compiled differently than how it appears in editors, leading to
|
|
possible security vulnerabilities.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic twice because there are
|
|
hidden characters at the start and end of the label string:
|
|
|
|
```dart
|
|
var label = '[!I!]nteractive text[!'!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the code points are intended to be included in the string literal,
|
|
then escape them:
|
|
|
|
```dart
|
|
var label = '\u202AInteractive text\u202C';
|
|
```
|
|
|
|
If the code points aren't intended to be included in the string literal,
|
|
then remove them:
|
|
|
|
```dart
|
|
var label = 'Interactive text';
|
|
```
|
|
typeCheckIsNotNull:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: typeCheckWithNull
|
|
problemMessage: "Tests for non-null should be done with '!= null'."
|
|
correctionMessage: "Try replacing the 'is! Null' check with '!= null'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a type check (using the
|
|
`as` operator) where the type is `Null`. There's only one value whose type
|
|
is `Null`, so the code is both more readable and more performant when it
|
|
tests for `null` explicitly.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the code is testing to
|
|
see whether the value of `s` is `null` by using a type check:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if ([!s is Null!]) {
|
|
return;
|
|
}
|
|
print(s);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the code is testing to
|
|
see whether the value of `s` is something other than `null` by using a type
|
|
check:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if ([!s is! Null!]) {
|
|
print(s);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Replace the type check with the equivalent comparison with `null`:
|
|
|
|
```dart
|
|
void f(String? s) {
|
|
if (s == null) {
|
|
return;
|
|
}
|
|
print(s);
|
|
}
|
|
```
|
|
typeCheckIsNull:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: typeCheckWithNull
|
|
problemMessage: "Tests for null should be done with '== null'."
|
|
correctionMessage: "Try replacing the 'is Null' check with '== null'."
|
|
hasPublishedDocs: true
|
|
undefinedHiddenName:
|
|
type: staticWarning
|
|
parameters:
|
|
String library: the name of the library being imported
|
|
String name: the name in the hide clause that isn't defined in the library
|
|
problemMessage: "The library '#library' doesn't export a member with the hidden name '#name'."
|
|
correctionMessage: Try removing the name from the list of hidden members.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a hide combinator includes a
|
|
name that isn't defined by the library being imported.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `dart:math` doesn't
|
|
define the name `String`:
|
|
|
|
```dart
|
|
import 'dart:math' hide [!String!], max;
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a different name should be hidden, then correct the name. Otherwise,
|
|
remove the name from the list:
|
|
|
|
```dart
|
|
import 'dart:math' hide max;
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
undefinedReferencedParameter:
|
|
type: staticWarning
|
|
parameters:
|
|
String undefinedParameterName: the name of the undefined parameter
|
|
String targetedMemberName: the name of the targeted member
|
|
problemMessage: "The parameter '#undefinedParameterName' isn't defined by '#targetedMemberName'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an annotation of the form
|
|
[`UseResult.unless(parameterDefined: parameterName)`][meta-UseResult]
|
|
specifies a parameter name that isn't defined by the annotated function.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `f`
|
|
doesn't have a parameter named `b`:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@UseResult.unless(parameterDefined: [!'b'!])
|
|
int f([int? a]) => a ?? 0;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change the argument named `parameterDefined` to match the name of one of
|
|
the parameters to the function:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
@UseResult.unless(parameterDefined: 'a')
|
|
int f([int? a]) => a ?? 0;
|
|
```
|
|
undefinedShownName:
|
|
type: staticWarning
|
|
parameters:
|
|
String library: the name of the library being imported
|
|
String name: the name in the show clause that isn't defined in the library
|
|
problemMessage: "The library '#library' doesn't export a member with the shown name '#name'."
|
|
correctionMessage: Try removing the name from the list of shown members.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a show combinator includes a
|
|
name that isn't defined by the library being imported.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `dart:math` doesn't
|
|
define the name `String`:
|
|
|
|
```dart
|
|
import 'dart:math' show min, [!String!];
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If a different name should be shown, then correct the name. Otherwise,
|
|
remove the name from the list:
|
|
|
|
```dart
|
|
import 'dart:math' show min;
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
unignorableIgnore:
|
|
type: staticWarning
|
|
parameters:
|
|
String diagnosticName: the name of the non-diagnostic being ignored
|
|
problemMessage: "The diagnostic '#diagnosticName' can't be ignored."
|
|
correctionMessage: Try removing the name from the list, or removing the whole comment if this is the only name in the list.
|
|
hasPublishedDocs: false
|
|
unnecessaryCast:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Unnecessary cast.
|
|
correctionMessage: Try removing the cast.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value being cast is already
|
|
known to be of the type that it's being cast to.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `n` is already known to
|
|
be an `int` as a result of the `is` test:
|
|
|
|
```dart
|
|
void f(num n) {
|
|
if (n is int) {
|
|
([!n as int!]).isEven;
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary cast:
|
|
|
|
```dart
|
|
void f(num n) {
|
|
if (n is int) {
|
|
n.isEven;
|
|
}
|
|
}
|
|
```
|
|
unnecessaryCastPattern:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Unnecessary cast pattern.
|
|
correctionMessage: Try removing the cast pattern.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a cast pattern is used on a
|
|
value that is known to be of the specified type.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the cast `as num` is
|
|
known to always succeed because the type of `z` is `int`:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var z [!as!] num) {
|
|
print(z);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the cast pattern:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x case var z) {
|
|
print(z);
|
|
}
|
|
}
|
|
```
|
|
unnecessaryFinal:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: The keyword 'final' isn't necessary because the parameter is implicitly 'final'.
|
|
correctionMessage: Try removing the 'final'.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either a field initializing
|
|
parameter or a super parameter in a constructor has the keyword `final`.
|
|
In both cases the keyword is unnecessary because the parameter is
|
|
implicitly `final`.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the field initializing
|
|
parameter has the keyword `final`:
|
|
|
|
```dart
|
|
// @dart = 3.10
|
|
class A {
|
|
int value;
|
|
|
|
A([!final!] this.value);
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because the super parameter in
|
|
`B` has the keyword `final`:
|
|
|
|
```dart
|
|
// @dart = 3.10
|
|
class A {
|
|
A(int value);
|
|
}
|
|
|
|
class B extends A {
|
|
B([!final!] super.value);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary `final` keyword:
|
|
|
|
```dart
|
|
class A {
|
|
A(int value);
|
|
}
|
|
|
|
class B extends A {
|
|
B(super.value);
|
|
}
|
|
```
|
|
unnecessaryNanComparisonFalse:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryNanComparison
|
|
problemMessage: A double can't equal 'double.nan', so the condition is always 'false'.
|
|
correctionMessage: Try using 'double.isNan', or removing the condition.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a value is compared to
|
|
`double.nan` using either `==` or `!=`.
|
|
|
|
Dart follows the [IEEE 754] floating-point standard for the semantics of
|
|
floating point operations, which states that, for any floating point value
|
|
`x` (including NaN, positive infinity, and negative infinity),
|
|
- `NaN == x` is always false
|
|
- `NaN != x` is always true
|
|
|
|
As a result, comparing any value to NaN is pointless because the result is
|
|
already known (based on the comparison operator being used).
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `d` is being compared
|
|
to `double.nan`:
|
|
|
|
```dart
|
|
bool isNaN(double d) => d [!== double.nan!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Use the getter `double.isNaN` instead:
|
|
|
|
```dart
|
|
bool isNaN(double d) => d.isNaN;
|
|
```
|
|
unnecessaryNanComparisonTrue:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryNanComparison
|
|
problemMessage: A double can't equal 'double.nan', so the condition is always 'true'.
|
|
correctionMessage: Try using 'double.isNan', or removing the condition.
|
|
hasPublishedDocs: true
|
|
unnecessaryNoSuchMethod:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Unnecessary 'noSuchMethod' declaration."
|
|
correctionMessage: "Try removing the declaration of 'noSuchMethod'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when there's a declaration of
|
|
`noSuchMethod`, the only thing the declaration does is invoke the
|
|
overridden declaration, and the overridden declaration isn't the
|
|
declaration in `Object`.
|
|
|
|
Overriding the implementation of `Object`'s `noSuchMethod` (no matter what
|
|
the implementation does) signals to the analyzer that it shouldn't flag any
|
|
inherited abstract methods that aren't implemented in that class. This
|
|
works even if the overriding implementation is inherited from a superclass,
|
|
so there's no value to declare it again in a subclass.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the declaration of
|
|
`noSuchMethod` in `A` makes the declaration of `noSuchMethod` in `B`
|
|
unnecessary:
|
|
|
|
```dart
|
|
class A {
|
|
@override
|
|
dynamic noSuchMethod(x) => super.noSuchMethod(x);
|
|
}
|
|
class B extends A {
|
|
@override
|
|
dynamic [!noSuchMethod!](y) {
|
|
return super.noSuchMethod(y);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary declaration:
|
|
|
|
```dart
|
|
class A {
|
|
@override
|
|
dynamic noSuchMethod(x) => super.noSuchMethod(x);
|
|
}
|
|
class B extends A {}
|
|
```
|
|
unnecessaryNullComparisonAlwaysNullFalse:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryNullComparison
|
|
problemMessage: "The operand must be 'null', so the condition is always 'false'."
|
|
correctionMessage: Remove the condition.
|
|
hasPublishedDocs: true
|
|
unnecessaryNullComparisonAlwaysNullTrue:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryNullComparison
|
|
problemMessage: "The operand must be 'null', so the condition is always 'true'."
|
|
correctionMessage: Remove the condition.
|
|
hasPublishedDocs: true
|
|
unnecessaryNullComparisonNeverNullFalse:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryNullComparison
|
|
problemMessage: "The operand can't be 'null', so the condition is always 'false'."
|
|
correctionMessage: Try removing the condition, an enclosing condition, or the whole conditional statement.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when it finds an equality comparison
|
|
(either `==` or `!=`) with one operand of `null` and the other operand
|
|
can't be `null`. Such comparisons are always either `true` or `false`, so
|
|
they serve no purpose.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because `x` can never be
|
|
`null`, so the comparison always evaluates to `true`:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
if (x [!!= null!]) {
|
|
print(x);
|
|
}
|
|
}
|
|
```
|
|
|
|
The following code produces this diagnostic because `x` can never be
|
|
`null`, so the comparison always evaluates to `false`:
|
|
|
|
```dart
|
|
%ignore=dead_code
|
|
void f(int x) {
|
|
if (x [!== null!]) {
|
|
throw ArgumentError("x can't be null");
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the other operand should be able to be `null`, then change the type of
|
|
the operand:
|
|
|
|
```dart
|
|
void f(int? x) {
|
|
if (x != null) {
|
|
print(x);
|
|
}
|
|
}
|
|
```
|
|
|
|
If the other operand really can't be `null`, then remove the condition:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
print(x);
|
|
}
|
|
```
|
|
unnecessaryNullComparisonNeverNullTrue:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryNullComparison
|
|
problemMessage: "The operand can't be 'null', so the condition is always 'true'."
|
|
correctionMessage: Remove the condition.
|
|
hasPublishedDocs: true
|
|
unnecessaryQuestionMark:
|
|
type: staticWarning
|
|
parameters:
|
|
String typeName: the name of the type
|
|
problemMessage: "The '?' is unnecessary because '#typeName' is nullable without it."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when either the type `dynamic` or the
|
|
type `Null` is followed by a question mark. Both of these types are
|
|
inherently nullable so the question mark doesn't change the semantics.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the question mark
|
|
following `dynamic` isn't necessary:
|
|
|
|
```dart
|
|
dynamic[!?!] x;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unneeded question mark:
|
|
|
|
```dart
|
|
dynamic x;
|
|
```
|
|
unnecessarySetLiteral:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Braces unnecessarily wrap this expression in a set literal.
|
|
correctionMessage: Try removing the set literal around the expression.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function that has a return
|
|
type of `void`, `Future<void>`, or `FutureOr<void>` uses an expression
|
|
function body (`=>`) and the returned value is a literal set containing a
|
|
single element.
|
|
|
|
Although the language allows it, returning a value from a `void` function
|
|
isn't useful because it can't be used at the call site. In this particular
|
|
case the return is often due to a misunderstanding about the syntax. The
|
|
braces aren't necessary and can be removed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the closure being
|
|
passed to `g` has a return type of `void`, but is returning a set:
|
|
|
|
```dart
|
|
void f() {
|
|
g(() => [!{1}!]);
|
|
}
|
|
|
|
void g(void Function() p) {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the braces from around the value:
|
|
|
|
```dart
|
|
void f() {
|
|
g(() => 1);
|
|
}
|
|
|
|
void g(void Function() p) {}
|
|
```
|
|
unnecessaryTypeCheckFalse:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryTypeCheck
|
|
problemMessage: "Unnecessary type check; the result is always 'false'."
|
|
correctionMessage: Try correcting the type check, or removing the type check.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the value of a type check (using
|
|
either `is` or `is!`) is known at compile time.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the test `a is Object?`
|
|
is always `true`:
|
|
|
|
```dart
|
|
bool f<T>(T a) => [!a is Object?!];
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the type check doesn't check what you intended to check, then change the
|
|
test:
|
|
|
|
```dart
|
|
bool f<T>(T a) => a is Object;
|
|
```
|
|
|
|
If the type check does check what you intended to check, then replace the
|
|
type check with its known value or completely remove it:
|
|
|
|
```dart
|
|
bool f<T>(T a) => true;
|
|
```
|
|
unnecessaryTypeCheckTrue:
|
|
type: staticWarning
|
|
parameters: none
|
|
sharedName: unnecessaryTypeCheck
|
|
problemMessage: "Unnecessary type check; the result is always 'true'."
|
|
correctionMessage: Try correcting the type check, or removing the type check.
|
|
hasPublishedDocs: true
|
|
unnecessaryWildcardPattern:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: Unnecessary wildcard pattern.
|
|
correctionMessage: Try removing the wildcard pattern.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a wildcard pattern is used in
|
|
either an and (`&&`) pattern or an or (`||`) pattern.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the wildcard pattern
|
|
(`_`) will always succeed, making it's use in an and pattern unnecessary:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case [!_!] && 0) {}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the use of the wildcard pattern:
|
|
|
|
```dart
|
|
void f(Object? x) {
|
|
if (x case 0) {}
|
|
}
|
|
```
|
|
unreachableSwitchCase:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "This case is covered by the previous cases."
|
|
correctionMessage: Try removing the case clause, or restructuring the preceding patterns.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `case` clause in a `switch`
|
|
statement doesn't match anything because all of the matchable values are
|
|
matched by an earlier `case` clause.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value `1` was
|
|
matched in the preceding case:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
switch (x) {
|
|
case 1:
|
|
print('one');
|
|
[!case!] 1:
|
|
print('two');
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Change one or both of the conflicting cases to match different values:
|
|
|
|
```dart
|
|
void f(int x) {
|
|
switch (x) {
|
|
case 1:
|
|
print('one');
|
|
case 2:
|
|
print('two');
|
|
}
|
|
}
|
|
```
|
|
unreachableSwitchDefault:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "This default clause is covered by the previous cases."
|
|
correctionMessage: Try removing the default clause, or restructuring the preceding patterns.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `default` clause in a
|
|
`switch` statement doesn't match anything because all of the matchable
|
|
values are matched by an earlier `case` clause.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the values `E.e1` and
|
|
`E.e2` were matched in the preceding cases:
|
|
|
|
```dart
|
|
enum E { e1, e2 }
|
|
|
|
void f(E x) {
|
|
switch (x) {
|
|
case E.e1:
|
|
print('one');
|
|
case E.e2:
|
|
print('two');
|
|
[!default!]:
|
|
print('other');
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unnecessary `default` clause:
|
|
|
|
```dart
|
|
enum E { e1, e2 }
|
|
void f(E x) {
|
|
switch (x) {
|
|
case E.e1:
|
|
print('one');
|
|
case E.e2:
|
|
print('two');
|
|
}
|
|
}
|
|
```
|
|
unusedCatchClause:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the exception variable
|
|
problemMessage: "The exception variable '#name' isn't used, so the 'catch' clause can be removed."
|
|
correctionMessage: Try removing the catch clause.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a `catch` clause is found, and
|
|
neither the exception parameter nor the optional stack trace parameter are
|
|
used in the `catch` block.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `e` isn't referenced:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
int.parse(';');
|
|
} on FormatException catch ([!e!]) {
|
|
// ignored
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Remove the unused `catch` clause:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
int.parse(';');
|
|
} on FormatException {
|
|
// ignored
|
|
}
|
|
}
|
|
```
|
|
unusedCatchStack:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the stack trace variable
|
|
problemMessage: "The stack trace variable '#name' isn't used and can be removed."
|
|
correctionMessage: Try removing the stack trace variable, or using it.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when the stack trace parameter in a
|
|
`catch` clause isn't referenced within the body of the `catch` block.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because `stackTrace` isn't
|
|
referenced:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} catch (exception, [!stackTrace!]) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you need to reference the stack trace parameter, then add a reference to
|
|
it. Otherwise, remove it:
|
|
|
|
```dart
|
|
void f() {
|
|
try {
|
|
// ...
|
|
} catch (exception) {
|
|
// ...
|
|
}
|
|
}
|
|
```
|
|
unusedElement:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name that is declared but not referenced
|
|
problemMessage: "The declaration '#name' isn't referenced."
|
|
correctionMessage: "Try removing the declaration of '#name'."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a private declaration isn't
|
|
referenced in the library that contains the declaration. The following
|
|
kinds of declarations are analyzed:
|
|
- Private top-level declarations and all of their members
|
|
- Private members of public declarations
|
|
|
|
Not all references to an element will mark it as "used":
|
|
- Assigning a value to a top-level variable (with a standard `=`
|
|
assignment, or a null-aware `??=` assignment) does not count as using
|
|
it.
|
|
- Referring to an element in a doc comment reference does not count as
|
|
using it.
|
|
- Referring to a class, mixin, or enum on the right side of an `is`
|
|
expression does not count as using it.
|
|
|
|
#### Example
|
|
|
|
Assuming that no code in the library references `_C`, the following code
|
|
produces this diagnostic:
|
|
|
|
```dart
|
|
class [!_C!] {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the declaration isn't needed, then remove it.
|
|
|
|
If the declaration is intended to be used, then add the code to use it.
|
|
unusedElementParameter:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the parameter that is declared but not used
|
|
problemMessage: "A value for optional parameter '#name' isn't ever given."
|
|
correctionMessage: Try removing the unused parameter.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a value is never passed for an
|
|
optional parameter declared within a private declaration.
|
|
|
|
#### Example
|
|
|
|
Assuming that no code in the library passes a value for `y` in any
|
|
invocation of `_m`, the following code produces this diagnostic:
|
|
|
|
```dart
|
|
class C {
|
|
void _m(int x, [int? [!y!]]) {}
|
|
|
|
void n() => _m(0);
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the declaration isn't needed, then remove it:
|
|
|
|
```dart
|
|
class C {
|
|
void _m(int x) {}
|
|
|
|
void n() => _m(0);
|
|
}
|
|
```
|
|
|
|
If the declaration is intended to be used, then add the code to use it.
|
|
unusedField:
|
|
type: staticWarning
|
|
parameters:
|
|
String fieldName: the name of the unused field
|
|
problemMessage: "The value of the field '#fieldName' isn't used."
|
|
correctionMessage: Try removing the field, or using it.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a private field is declared but
|
|
never read, even if it's written in one or more places.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field
|
|
`_originalValue` isn't read anywhere in the library:
|
|
|
|
```dart
|
|
class C {
|
|
final String [!_originalValue!];
|
|
final String _currentValue;
|
|
|
|
C(this._originalValue) : _currentValue = _originalValue;
|
|
|
|
String get value => _currentValue;
|
|
}
|
|
```
|
|
|
|
It might appear that the field `_originalValue` is being read in the
|
|
initializer (`_currentValue = _originalValue`), but that is actually a
|
|
reference to the parameter of the same name, not a reference to the field.
|
|
|
|
#### Common fixes
|
|
|
|
If the field isn't needed, then remove it.
|
|
|
|
If the field was intended to be used, then add the missing code.
|
|
unusedFieldFromPrimaryConstructor:
|
|
type: staticWarning
|
|
parameters:
|
|
String fieldName: the name of the unused field
|
|
String keyword: the keyword to remove
|
|
problemMessage: "The value of the field '#fieldName' isn't used."
|
|
correctionMessage: Try removing the '#keyword' keyword to avoid declaring a field, or try using the field, or removing it.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a private field is declared in
|
|
a primary constructor but never read, even if it's written in one or more
|
|
places.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the field
|
|
`_i` isn't read anywhere in the library:
|
|
|
|
```dart
|
|
class C(final int [!_i!]);
|
|
```
|
|
|
|
The primary constructor declares a field because the keyword `final` is
|
|
used. (Using the `var` keyword also declares a field.)
|
|
|
|
#### Common fixes
|
|
|
|
If the parameter is still necessary, but the associated field is not, then
|
|
remove the `final` or `var` keyword:
|
|
|
|
```dart
|
|
class C(int _i);
|
|
```
|
|
|
|
If the parameter is also unnecessary, then remove it (which also removes
|
|
the associated field).
|
|
|
|
```dart
|
|
class C {}
|
|
```
|
|
|
|
If the field was intended to be used, then add the missing code.
|
|
unusedImport:
|
|
type: staticWarning
|
|
parameters:
|
|
String uriStr: the content of the unused import's URI
|
|
problemMessage: "Unused import: '#uriStr'."
|
|
correctionMessage: Try removing the import directive.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import isn't needed because
|
|
none of the names that are imported are referenced within the importing
|
|
library.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because nothing defined in
|
|
`dart:async` is referenced in the library:
|
|
|
|
```dart
|
|
import [!'dart:async'!];
|
|
|
|
void main() {}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the import isn't needed, then remove it.
|
|
|
|
If some of the imported names are intended to be used, then add the missing
|
|
code.
|
|
unusedLabel:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the label that isn't used
|
|
problemMessage: "The label '#name' isn't used."
|
|
correctionMessage: "Try removing the label, or using it in either a 'break' or 'continue' statement."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a label that isn't used is
|
|
found.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the label `loop` isn't
|
|
referenced anywhere in the method:
|
|
|
|
```dart
|
|
void f(int limit) {
|
|
[!loop:!] for (int i = 0; i < limit; i++) {
|
|
print(i);
|
|
}
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the label isn't needed, then remove it:
|
|
|
|
```dart
|
|
void f(int limit) {
|
|
for (int i = 0; i < limit; i++) {
|
|
print(i);
|
|
}
|
|
}
|
|
```
|
|
|
|
If the label is needed, then use it:
|
|
|
|
```dart
|
|
void f(int limit) {
|
|
loop: for (int i = 0; i < limit; i++) {
|
|
print(i);
|
|
if (i != 0) {
|
|
break loop;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
TODO(brianwilkerson): Highlight the identifier without the colon.
|
|
multipleCombinators:
|
|
type: staticWarning
|
|
parameters: none
|
|
problemMessage: "Using multiple 'hide' or 'show' combinators is never necessary and often produces surprising results."
|
|
correctionMessage: "Try using a single combinator."
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when an import or export directive
|
|
contains more than one combinator.
|
|
|
|
#### Examples
|
|
|
|
The following code produces this diagnostic because the second `show`
|
|
combinator hides `List` and `int`:
|
|
|
|
```dart
|
|
import 'dart:core' [!show Future, List, int show Future!];
|
|
|
|
var x = Future.value(1);
|
|
```
|
|
|
|
The following code produces this diagnostic because
|
|
the second `hide` combinator is redundant:
|
|
|
|
```dart
|
|
import 'dart:math' [!hide Random, max, min hide min!];
|
|
|
|
var x = pi;
|
|
```
|
|
|
|
The following codes produce this diagnostic because
|
|
the `hide` combinator is redundant:
|
|
|
|
```dart
|
|
import 'dart:math' [!show Random, max hide min!];
|
|
|
|
var x = max(0, 1);
|
|
var r = Random();
|
|
```
|
|
|
|
The following code produces this diagnostic because
|
|
the `show` combinator already hides `Random` and `max`,
|
|
so the `hide` combinator is redundant:
|
|
|
|
```dart
|
|
import 'dart:math' [!hide Random, max show min!];
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you prefer to list the names that should be visible,
|
|
then use a single `show` combinator:
|
|
|
|
```dart
|
|
import 'dart:math' show min;
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
|
|
If you prefer to list the names that should be hidden,
|
|
then use a single `hide` combinator:
|
|
|
|
```dart
|
|
import 'dart:math' hide Random, max, min;
|
|
|
|
var x = pi;
|
|
```
|
|
unusedLocalVariable:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the unused variable
|
|
problemMessage: "The value of the local variable '#name' isn't used."
|
|
correctionMessage: Try removing the variable or using it.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a local variable is declared but
|
|
never read, even if it's written in one or more places.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the value of `count` is
|
|
never read:
|
|
|
|
```dart
|
|
void main() {
|
|
int [!count!] = 0;
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the variable isn't needed, then remove it.
|
|
|
|
If the variable was intended to be used, then add the missing code.
|
|
unusedResult:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the annotated method, property or function
|
|
problemMessage: "The value of '#name' should be used."
|
|
correctionMessage: Try using the result by invoking a member, passing it to a function, or returning it from this function.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a function annotated with
|
|
[`useResult`][meta-useResult] is invoked, and the value returned by that
|
|
function isn't used. The value is considered to be used if a member of the
|
|
value is invoked, if the value is passed to another function, or if the
|
|
value is assigned to a variable or field.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the invocation of
|
|
`c.a()` isn't used, even though the method `a` is annotated with
|
|
[`useResult`][meta-useResult]:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@useResult
|
|
int a() => 0;
|
|
|
|
int b() => 0;
|
|
}
|
|
|
|
void f(C c) {
|
|
c.[!a!]();
|
|
}
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If you intended to invoke the annotated function, then use the value that
|
|
was returned:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@useResult
|
|
int a() => 0;
|
|
|
|
int b() => 0;
|
|
}
|
|
|
|
void f(C c) {
|
|
print(c.a());
|
|
}
|
|
```
|
|
|
|
If you intended to invoke a different function, then correct the name of
|
|
the function being invoked:
|
|
|
|
```dart
|
|
import 'package:meta/meta.dart';
|
|
|
|
class C {
|
|
@useResult
|
|
int a() => 0;
|
|
|
|
int b() => 0;
|
|
}
|
|
|
|
void f(C c) {
|
|
c.b();
|
|
}
|
|
```
|
|
unusedResultWithMessage:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name of the annotated method, property or function
|
|
String message: message details
|
|
sharedName: unusedResult
|
|
problemMessage: "'#name' should be used. #message."
|
|
correctionMessage: Try using the result by invoking a member, passing it to a function, or returning it from this function.
|
|
hasPublishedDocs: true
|
|
comment: |-
|
|
The result of invoking a method, property, or function annotated with
|
|
`@useResult` must be used (assigned, passed to a function as an argument,
|
|
or returned by a function).
|
|
unusedShownName:
|
|
type: staticWarning
|
|
parameters:
|
|
String name: the name that is shown but not used
|
|
problemMessage: "The name #name is shown, but isn't used."
|
|
correctionMessage: Try removing the name from the list of shown members.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a show combinator includes a
|
|
name that isn't used within the library. Because it isn't referenced, the
|
|
name can be removed.
|
|
|
|
#### Example
|
|
|
|
The following code produces this diagnostic because the function `max`
|
|
isn't used:
|
|
|
|
```dart
|
|
import 'dart:math' show min, [!max!];
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
Either use the name or remove it:
|
|
|
|
```dart
|
|
import 'dart:math' show min;
|
|
|
|
var x = min(0, 1);
|
|
```
|
|
uriDoesNotExistInDocImport:
|
|
type: staticWarning
|
|
parameters:
|
|
String uriStr: the URI pointing to a nonexistent file
|
|
problemMessage: "Target of URI doesn't exist: '#uriStr'."
|
|
correctionMessage: Try creating the file referenced by the URI, or try using a URI for a file that does exist.
|
|
hasPublishedDocs: true
|
|
documentation: |-
|
|
#### Description
|
|
|
|
The analyzer produces this diagnostic when a doc-import is found where
|
|
the URI refers to a file that doesn't exist.
|
|
|
|
#### Examples
|
|
|
|
If the file `lib.dart` doesn't exist, the following code produces this
|
|
diagnostic:
|
|
|
|
```dart
|
|
/// @docImport [!'lib.dart'!];
|
|
library;
|
|
```
|
|
|
|
#### Common fixes
|
|
|
|
If the URI was mistyped or invalid, then correct the URI.
|
|
|
|
If the URI is correct, then create the file.
|