blob: 74578c1d90c978d45a006cb58cb1fa548a032d27 [file] [log] [blame] [edit]
# Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This file contains error messages that are shared between the analyzer and the
# front end.
# See pkg/front_end/messages.yaml for documentation about this file.
ExperimentNotEnabled:
type: syntacticError
parameters:
String string: undocumented
String string2: undocumented
problemMessage: "This requires the '#string' language feature to be enabled."
correctionMessage: "Try updating your pubspec.yaml to set the minimum SDK constraint to #string2 or higher, and running 'pub get'."
analyzerCode: ParserErrorCode.EXPERIMENT_NOT_ENABLED
hasPublishedDocs: false
ExperimentNotEnabledOffByDefault:
type: syntacticError
parameters:
String string: undocumented
problemMessage: "This requires the experimental '#string' language feature to be enabled."
correctionMessage: "Try passing the '--enable-experiment=#string' command line option."
analyzerCode: ParserErrorCode.EXPERIMENT_NOT_ENABLED_OFF_BY_DEFAULT
hasPublishedDocs: false
script: |
// @dart=3.5
void foo() {
int i = 42_42_42_42;
}
RecordLiteralOnePositionalFieldNoTrailingComma:
type: syntacticError
parameters: none
problemMessage: "A record literal with exactly one positional field requires a trailing comma."
correctionMessage: "Try adding a trailing comma."
analyzerCode: ParserErrorCode.RECORD_LITERAL_ONE_POSITIONAL_NO_TRAILING_COMMA
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a record literal with a single
positional field doesn't have a trailing comma after the field.
In some locations a record literal with a single positional field could
also be a parenthesized expression. A trailing comma is required to
disambiguate these two valid interpretations.
#### Example
The following code produces this diagnostic because the record literal has
one positional field but doesn't have a trailing comma:
```dart
var r = const (1[!)!];
```
#### Common fixes
Add a trailing comma:
```dart
var r = const (1,);
```
script: |
main() {
var record = const (1);
}
RecordLiteralZeroFieldsWithTrailingComma:
type: syntacticError
parameters: none
problemMessage: "A record literal without fields can't have a trailing comma."
correctionMessage: "Try removing the trailing comma."
analyzerCode: ParserErrorCode.EMPTY_RECORD_LITERAL_WITH_COMMA
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a record literal that has no
fields has a trailing comma. Empty record literals can't contain a comma.
#### Example
The following code produces this diagnostic because the empty record
literal has a trailing comma:
```dart
var r = ([!,!]);
```
#### Common fixes
If the record is intended to be empty, then remove the comma:
```dart
var r = ();
```
If the record is intended to have one or more fields, then add the
expressions used to compute the values of those fields:
```dart
var r = (3, 4);
```
script: |
main() {
var record = (,);
}
EmptyRecordTypeNamedFieldsList:
type: syntacticError
parameters: none
problemMessage: "The list of named fields in a record type can't be empty."
correctionMessage: "Try adding a named field to the list."
analyzerCode: ParserErrorCode.EMPTY_RECORD_TYPE_NAMED_FIELDS_LIST
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a record type has an empty list
of named fields.
#### Example
The following code produces this diagnostic because the record type has an
empty list of named fields:
```dart
void f((int, int, {[!}!]) r) {}
```
#### Common fixes
If the record is intended to have named fields, then add the types and
names of the fields:
```dart
void f((int, int, {int z}) r) {}
```
If the record isn't intended to have named fields, then remove the curly
braces:
```dart
void f((int, int) r) {}
```
script: |
main() {
(int, int, {/*missing*/}) record = (1, 2,);
}
RecordTypeZeroFieldsButTrailingComma:
type: syntacticError
parameters: none
problemMessage: "A record type without fields can't have a trailing comma."
correctionMessage: "Try removing the trailing comma."
analyzerCode: ParserErrorCode.EMPTY_RECORD_TYPE_WITH_COMMA
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a record type that has no
fields has a trailing comma. Empty record types can't contain a comma.
#### Example
The following code produces this diagnostic because the empty record type
has a trailing comma:
```dart
void f(([!,!]) r) {}
```
#### Common fixes
If the record type is intended to be empty, then remove the comma:
```dart
void f(() r) {}
```
If the record type is intended to have one or more fields, then add the
types of those fields:
```dart
void f((int, int) r) {}
```
script: |
main() {
(,) record = ();
}
RecordTypeOnePositionalFieldNoTrailingComma:
type: syntacticError
parameters: none
problemMessage: "A record type with exactly one positional field requires a trailing comma."
correctionMessage: "Try adding a trailing comma."
analyzerCode: ParserErrorCode.RECORD_TYPE_ONE_POSITIONAL_NO_TRAILING_COMMA
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a record type annotation with a
single positional field doesn't have a trailing comma after the field.
In some locations a record type with a single positional field could also
be a parenthesized expression. A trailing comma is required to
disambiguate these two valid interpretations.
#### Example
The following code produces this diagnostic because the record type has
one positional field, but doesn't have a trailing comma:
```dart
void f((int[!)!] r) {}
```
#### Common fixes
Add a trailing comma:
```dart
void f((int,) r) {}
```
script: |
main() {
(int /* missing trailing comma */) record = const (1, );
}
ExpectedElseOrComma:
type: syntacticError
parameters: none
problemMessage: "Expected 'else' or comma."
analyzerCode: ParserErrorCode.EXPECTED_ELSE_OR_COMMA
hasPublishedDocs: false
script: |
void foo(int i) {
var x = [
if (i > 2) 2
2
];
}
ExpectedStatement:
type: syntacticError
parameters: none
problemMessage: "Expected a statement."
analyzerCode: ParserErrorCode.MISSING_STATEMENT
hasPublishedDocs: false
statement: "void;"
ExpectedInstead:
type: syntacticError
parameters:
String string: undocumented
problemMessage: "Expected '#string' instead of this."
# This is an alternative to ExpectedButGot when the last consumed token
# should be replaced with a different token.
#
# For example, this is ok...
#
# mixin Foo extends Bar {
# ^^^^^^^
# Expected 'on' before this
#
# but this is easier for the user...
#
# mixin Foo extends Bar {
# ^^^^^^^
# Expected 'on' instead of this
#
analyzerCode: ParserErrorCode.EXPECTED_INSTEAD
hasPublishedDocs: false
script:
- "class B {} mixin A extends B { }"
MultipleLibraryDirectives:
type: syntacticError
parameters: none
problemMessage: "Only one library directive may be declared in a file."
correctionMessage: "Try removing all but one of the library directives."
analyzerCode: ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES
hasPublishedDocs: false
script:
library foo;
library bar;
MultipleExtends:
type: syntacticError
parameters: none
problemMessage: "Each class definition can have at most one extends clause."
correctionMessage: "Try choosing one superclass and define your class to implement (or mix in) the others."
analyzerCode: ParserErrorCode.MULTIPLE_EXTENDS_CLAUSES
hasPublishedDocs: false
script:
- "class B{} class C{} class A extends B extends C {}"
- "class B{} class C{} class A extends B, C {}"
MultipleWith:
type: syntacticError
parameters: none
problemMessage: "Each class definition can have at most one with clause."
correctionMessage: "Try combining all of the with clauses into a single clause."
analyzerCode: ParserErrorCode.MULTIPLE_WITH_CLAUSES
hasPublishedDocs: false
script: "class A extends B with C, D with E {}"
exampleAllowOtherCodes: true
WithBeforeExtends:
type: syntacticError
parameters: none
problemMessage: "The extends clause must be before the with clause."
correctionMessage: "Try moving the extends clause before the with clause."
analyzerCode: ParserErrorCode.WITH_BEFORE_EXTENDS
hasPublishedDocs: false
script: "mixin B {} class C {} class A with B extends C {}"
ImplementsBeforeExtends:
type: syntacticError
parameters: none
problemMessage: "The extends clause must be before the implements clause."
correctionMessage: "Try moving the extends clause before the implements clause."
analyzerCode: ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS
hasPublishedDocs: false
script: "class A implements B extends C {}"
exampleAllowOtherCodes: true
ImplementsBeforeOn:
type: syntacticError
parameters: none
problemMessage: "The on clause must be before the implements clause."
correctionMessage: "Try moving the on clause before the implements clause."
analyzerCode: ParserErrorCode.IMPLEMENTS_BEFORE_ON
hasPublishedDocs: false
script: "mixin A implements B on C {}"
exampleAllowOtherCodes: true
ImplementsBeforeWith:
type: syntacticError
parameters: none
problemMessage: "The with clause must be before the implements clause."
correctionMessage: "Try moving the with clause before the implements clause."
analyzerCode: ParserErrorCode.IMPLEMENTS_BEFORE_WITH
hasPublishedDocs: false
script: "class A extends B implements C with D {}"
exampleAllowOtherCodes: true
MultipleClauses:
type: syntacticError
parameters:
String string: undocumented
String string2: undocumented
problemMessage: "Each '#string' definition can have at most one '#string2' clause."
correctionMessage: "Try combining all of the '#string2' clauses into a single clause."
analyzerCode: ParserErrorCode.MULTIPLE_CLAUSES
hasPublishedDocs: false
script:
- "mixin B {} enum A implements B implements C, D { v; }"
- "mixin B {} enum A with B with C, D { v; }"
OutOfOrderClauses:
type: syntacticError
parameters:
String string: undocumented
String string2: undocumented
problemMessage: "The '#string' clause must come before the '#string2' clause."
correctionMessage: "Try moving the '#string' clause before the '#string2' clause."
analyzerCode: ParserErrorCode.OUT_OF_ORDER_CLAUSES
hasPublishedDocs: false
script: "class B {} class D {} enum A implements B with D { v; }"
MultipleOnClauses:
type: syntacticError
parameters: none
problemMessage: "Each mixin definition can have at most one on clause."
correctionMessage: "Try combining all of the on clauses into a single clause."
analyzerCode: ParserErrorCode.MULTIPLE_ON_CLAUSES
hasPublishedDocs: false
script: "mixin A on B on C, D {}"
exampleAllowOtherCodes: true
MixinWithClause:
type: syntacticError
parameters: none
problemMessage: "A mixin can't have a with clause."
analyzerCode: ParserErrorCode.MIXIN_WITH_CLAUSE
hasPublishedDocs: false
script: "mixin M {} mixin N with M {}"
ExpectedClassBody:
type: syntacticError
parameters: none
problemMessage: "A class declaration must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_CLASS_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
class Class
ExpectedMixinBody:
type: syntacticError
parameters: none
problemMessage: "A mixin declaration must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_MIXIN_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
mixin Mixin
ExpectedExtensionBody:
type: syntacticError
parameters: none
problemMessage: "An extension declaration must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_EXTENSION_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
extension Extension on int
ExpectedExtensionTypeBody:
type: syntacticError
parameters: none
problemMessage: "An extension type declaration must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_EXTENSION_TYPE_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
extension type ExtensionType(int i)
ExpectedTryStatementBody:
type: syntacticError
parameters: none
problemMessage: "A try statement must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_TRY_STATEMENT_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
method() {
try finally {}
}
ExpectedCatchClauseBody:
type: syntacticError
parameters: none
problemMessage: "A catch clause must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_CATCH_CLAUSE_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
method() {
try {} catch (_);
}
ExpectedFinallyClauseBody:
type: syntacticError
parameters: none
problemMessage: "A finally clause must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_FINALLY_CLAUSE_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
method() {
try {} finally;
}
ExpectedSwitchExpressionBody:
type: syntacticError
parameters: none
problemMessage: "A switch expression must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_SWITCH_EXPRESSION_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
method(Never n) => switch (n);
ExpectedSwitchStatementBody:
type: syntacticError
parameters: none
problemMessage: "A switch statement must have a body, even if it is empty."
correctionMessage: "Try adding an empty body."
analyzerCode: ParserErrorCode.EXPECTED_SWITCH_STATEMENT_BODY
hasPublishedDocs: false
sharedName: EXPECTED_BODY
script: |
method(Never n) {
switch (n);
}
ExpectedIdentifierButGotKeyword:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "'#lexeme' can't be used as an identifier because it's a keyword."
correctionMessage: "Try renaming this to be an identifier that isn't a keyword."
analyzerCode: ParserErrorCode.EXPECTED_IDENTIFIER_BUT_GOT_KEYWORD
hasPublishedDocs: false
script: "var default = 42;"
EqualityCannotBeEqualityOperand:
type: syntacticError
parameters: none
problemMessage: "A comparison expression can't be an operand of another comparison expression."
correctionMessage: "Try putting parentheses around one of the comparisons."
analyzerCode: ParserErrorCode.EQUALITY_CANNOT_BE_EQUALITY_OPERAND
hasPublishedDocs: false
exampleAllowOtherCodes: true
script:
- "main() { var b = a < b < c; }"
- "main() { var b = a == b != c; }"
VarAsTypeName:
type: syntacticError
parameters: none
problemMessage: "The keyword 'var' can't be used as a type name."
analyzerCode: ParserErrorCode.VAR_AS_TYPE_NAME
hasPublishedDocs: false
script:
- "class A { Map<String, var> m; }"
exampleAllowOtherCodes: true
MissingExpressionInThrow:
type: syntacticError
parameters: none
problemMessage: "Missing expression after 'throw'."
correctionMessage: "Add an expression after 'throw' or use 'rethrow' to throw a caught exception"
analyzerCode: ParserErrorCode.MISSING_EXPRESSION_IN_THROW
hasPublishedDocs: false
statement:
- "throw;"
MissingConstFinalVarOrType:
type: syntacticError
parameters: none
problemMessage: "Variables must be declared using the keywords 'const', 'final', 'var' or a type name."
correctionMessage: "Try adding the name of the type of the variable or the keyword 'var'."
analyzerCode: ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE
hasPublishedDocs: false
script:
- "class C { static f; }"
FunctionTypedParameterVar:
type: syntacticError
parameters: none
problemMessage: "Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type."
correctionMessage: "Try replacing the keyword with a return type."
analyzerCode: ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR
hasPublishedDocs: false
script:
- "void f(const x()) {}"
- "void f(final x()) {}"
- "void f(var x()) {}"
exampleAllowOtherCodes: true
AbstractClassMember:
type: syntacticError
parameters: none
problemMessage: "Members of classes can't be declared to be 'abstract'."
correctionMessage: "Try removing the 'abstract' keyword. You can add the 'abstract' keyword before the class declaration."
analyzerCode: ParserErrorCode.ABSTRACT_CLASS_MEMBER
hasPublishedDocs: false
script:
- |
abstract class C {abstract C.c();}
- |
abstract class C {abstract m();}
- |
abstract class C {abstract get m;}
- |
abstract class C {abstract set m(int x);}
AbstractExternalField:
type: syntacticError
parameters: none
problemMessage: "Fields can't be declared both 'abstract' and 'external'."
analyzerCode: ParserErrorCode.ABSTRACT_EXTERNAL_FIELD
hasPublishedDocs: false
correctionMessage: "Try removing the 'abstract' or 'external' keyword."
script:
- "abstract class C {abstract external var f;}"
- "abstract class C {external abstract var f;}"
AbstractStaticField:
type: syntacticError
parameters: none
problemMessage: "Static fields can't be declared 'abstract'."
analyzerCode: ParserErrorCode.ABSTRACT_STATIC_FIELD
hasPublishedDocs: false
correctionMessage: "Try removing the 'abstract' or 'static' keyword."
script:
- "abstract class C {abstract static var f;}"
AbstractLateField:
type: syntacticError
parameters: none
problemMessage: "Abstract fields cannot be late."
analyzerCode: ParserErrorCode.ABSTRACT_LATE_FIELD
hasPublishedDocs: false
correctionMessage: "Try removing the 'abstract' or 'late' keyword."
script:
- "abstract class C {abstract late var f;}"
AbstractFinalBaseClass:
type: syntacticError
parameters: none
problemMessage: "An 'abstract' class can't be declared as both 'final' and 'base'."
correctionMessage: "Try removing either the 'final' or 'base' keyword."
analyzerCode: ParserErrorCode.ABSTRACT_FINAL_BASE_CLASS
hasPublishedDocs: false
script:
- "abstract final base class C {}"
AbstractFinalInterfaceClass:
type: syntacticError
parameters: none
problemMessage: "An 'abstract' class can't be declared as both 'final' and 'interface'."
correctionMessage: "Try removing either the 'final' or 'interface' keyword."
analyzerCode: ParserErrorCode.ABSTRACT_FINAL_INTERFACE_CLASS
hasPublishedDocs: false
script:
- "abstract final interface class C {}"
AbstractSealedClass:
type: syntacticError
parameters: none
problemMessage: "A 'sealed' class can't be marked 'abstract' because it's already implicitly abstract."
correctionMessage: "Try removing the 'abstract' keyword."
analyzerCode: ParserErrorCode.ABSTRACT_SEALED_CLASS
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when a class is declared using both
the modifier `abstract` and the modifier `sealed`. Sealed classes are
implicitly abstract, so explicitly using both modifiers is not allowed.
#### Example
The following code produces this diagnostic because the class `C` is
declared using both `abstract` and `sealed`:
```dart
abstract [!sealed!] class C {}
```
#### Common fixes
If the class should be abstract but not sealed, then remove the `sealed`
modifier:
```dart
abstract class C {}
```
If the class should be both abstract and sealed, then remove the
`abstract` modifier:
```dart
sealed class C {}
```
script:
- "sealed abstract class C {}"
- "abstract sealed class C {}"
ClassInClass:
type: syntacticError
parameters: none
problemMessage: "Classes can't be declared inside other classes."
correctionMessage: "Try moving the class to the top-level."
analyzerCode: ParserErrorCode.CLASS_IN_CLASS
hasPublishedDocs: false
script:
- "class C { class B {} }"
EnumInClass:
type: syntacticError
parameters: none
problemMessage: "Enums can't be declared inside classes."
correctionMessage: "Try moving the enum to the top-level."
analyzerCode: ParserErrorCode.ENUM_IN_CLASS
hasPublishedDocs: false
script:
- "class Foo { enum Bar { Bar1, Bar2, Bar3 } }"
TypedefInClass:
type: syntacticError
parameters: none
problemMessage: "Typedefs can't be declared inside classes."
correctionMessage: "Try moving the typedef to the top-level."
analyzerCode: ParserErrorCode.TYPEDEF_IN_CLASS
hasPublishedDocs: false
script:
- "abstract class C { typedef int F(int x); }"
CovariantMember:
type: syntacticError
parameters: none
problemMessage: "Getters, setters and methods can't be declared to be 'covariant'."
correctionMessage: "Try removing the 'covariant' keyword."
analyzerCode: ParserErrorCode.COVARIANT_MEMBER
hasPublishedDocs: false
script:
- "class A { covariant get x => 0; }"
- "class A { covariant int m() => 0; }"
VarReturnType:
type: syntacticError
parameters: none
problemMessage: "The return type can't be 'var'."
correctionMessage: "Try removing the keyword 'var', or replacing it with the name of the return type."
analyzerCode: ParserErrorCode.VAR_RETURN_TYPE
hasPublishedDocs: false
script:
- "class C { var m() {} }"
- "class C { var C() {} }"
ConstClass:
type: syntacticError
parameters: none
problemMessage: "Classes can't be declared to be 'const'."
correctionMessage: "Try removing the 'const' keyword. If you're trying to indicate that instances of the class can be constants, place the 'const' keyword on the class' constructor(s)."
analyzerCode: ParserErrorCode.CONST_CLASS
hasPublishedDocs: false
script: "const class C {}"
ConstAndFinal:
type: syntacticError
parameters: none
problemMessage: "Members can't be declared to be both 'const' and 'final'."
correctionMessage: "Try removing either the 'const' or 'final' keyword."
analyzerCode: ParserErrorCode.CONST_AND_FINAL
hasPublishedDocs: false
declaration:
- "class C { static const final int x = 5; }"
- "class C { static final const int x = 5; }"
- "const final int x = 5;"
- "final const int x = 5;"
ConflictingModifiers:
type: syntacticError
parameters:
String string: undocumented
String string2: undocumented
problemMessage: "Members can't be declared to be both '#string' and '#string2'."
correctionMessage: "Try removing one of the keywords."
analyzerCode: ParserErrorCode.CONFLICTING_MODIFIERS
hasPublishedDocs: false
script:
- "class C { const var x; }"
- "class C { var const x; }"
exampleAllowOtherCodes: true
ConstFactory:
type: syntacticError
parameters: none
problemMessage: "Only redirecting factory constructors can be declared to be 'const'."
correctionMessage: "Try removing the 'const' keyword, or replacing the body with '=' followed by a valid target."
analyzerCode: ParserErrorCode.CONST_FACTORY
hasPublishedDocs: false
script: |
class C {
const factory C() => const C.internal();
const C.internal();
}
ModifierOutOfOrder:
type: syntacticError
parameters:
String string: undocumented
String string2: undocumented
problemMessage: "The modifier '#string' should be before the modifier '#string2'."
correctionMessage: "Try re-ordering the modifiers."
analyzerCode: ParserErrorCode.MODIFIER_OUT_OF_ORDER
hasPublishedDocs: false
script:
- "class C { factory const C() = prefix.B.foo; }"
- "class C { factory external C(); }"
- "class C { const external C(); }"
- "class C { static external f(); }"
- "class C { final static int f = 5; }"
- "class C { var static f; }"
- "var external foo; main(){}"
exampleAllowOtherCodes: true
TypeBeforeFactory:
type: syntacticError
parameters: none
problemMessage: "Factory constructors cannot have a return type."
correctionMessage: "Try removing the type appearing before 'factory'."
analyzerCode: ParserErrorCode.TYPE_BEFORE_FACTORY
hasPublishedDocs: false
script: |
class C {
T factory C() { return new C.constructor(); }
C.constructor();
}
ConstMethod:
type: syntacticError
parameters: none
problemMessage: "Getters, setters and methods can't be declared to be 'const'."
correctionMessage: "Try removing the 'const' keyword."
analyzerCode: ParserErrorCode.CONST_METHOD
hasPublishedDocs: false
script:
- "class C { const m() {} }"
CovariantAndStatic:
type: syntacticError
parameters: none
problemMessage: "Members can't be declared to be both 'covariant' and 'static'."
correctionMessage: "Try removing either the 'covariant' or 'static' keyword."
analyzerCode: ParserErrorCode.COVARIANT_AND_STATIC
hasPublishedDocs: false
script:
- "class A {} class C { covariant static A? f; }"
- "class A {} class C { static covariant A? f; }"
DuplicatedModifier:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "The modifier '#lexeme' was already specified."
correctionMessage: "Try removing all but one occurrence of the modifier."
analyzerCode: ParserErrorCode.DUPLICATED_MODIFIER
hasPublishedDocs: false
comment: |-
Parameters:
0: the modifier that was duplicated
exampleAllowOtherCodes: true
script:
- "class C { const const m; }"
- "class C { external external f(); }"
- "class C { final final m = 5; }"
- "class C { static static var m; }"
- "class C { var var m; }"
ExternalConstructorWithFieldInitializers:
type: syntacticError
parameters: none
problemMessage: "An external constructor can't initialize fields."
correctionMessage: "Try removing the field initializers, or removing the keyword 'external'."
analyzerCode: ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_FIELD_INITIALIZERS
hasPublishedDocs: false
script: |
class Foo {
var x = -1;
external Foo.x(this.x);
}
ExternalFactoryWithBody:
type: syntacticError
parameters: none
problemMessage: "External factories can't have a body."
correctionMessage: "Try removing the body of the factory, or removing the keyword 'external'."
analyzerCode: ParserErrorCode.EXTERNAL_FACTORY_WITH_BODY
hasPublishedDocs: false
script:
- "class C { external factory C() {} }"
exampleAllowOtherCodes: true
ExternalLateField:
type: syntacticError
parameters: none
problemMessage: "External fields cannot be late."
analyzerCode: ParserErrorCode.EXTERNAL_LATE_FIELD
hasPublishedDocs: false
correctionMessage: "Try removing the 'external' or 'late' keyword."
script:
- "external late var f;"
- "abstract class C {external late var f;}"
ExtraneousModifier:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "Can't have modifier '#lexeme' here."
correctionMessage: "Try removing '#lexeme'."
analyzerCode: ParserErrorCode.EXTRANEOUS_MODIFIER
hasPublishedDocs: false
script:
- "var abstract foo; main(){}"
- "var static foo; main(){}"
- "abstract var foo; main(){}"
- "static var foo; main(){}"
- "abstract foo; main(){}"
- "static foo; main(){}"
- "abstract enum foo {bar}"
- "abstract void foo() {}"
- "static void foo() {}"
- "abstract typedef foo();"
- "static typedef foo();"
exampleAllowOtherCodes: true
ExtraneousModifierInExtension:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "Can't have modifier '#lexeme' in an extension."
correctionMessage: "Try removing '#lexeme'."
analyzerCode: ParserErrorCode.INVALID_USE_OF_COVARIANT_IN_EXTENSION
hasPublishedDocs: true
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a member declared inside an
extension uses the keyword `covariant` in the declaration of a parameter.
Extensions aren't classes and don't have subclasses, so the keyword serves
no purpose.
#### Example
The following code produces this diagnostic because `i` is marked as being
covariant:
```dart
extension E on String {
void a([!covariant!] int i) {}
}
```
#### Common fixes
Remove the `covariant` keyword:
```dart
extension E on String {
void a(int i) {}
}
```
script:
- "extension on String { foo(covariant String child) {} }"
ExtraneousModifierInExtensionType:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "Can't have modifier '#lexeme' in an extension type."
correctionMessage: "Try removing '#lexeme'."
analyzerCode: ParserErrorCode.EXTRANEOUS_MODIFIER_IN_EXTENSION_TYPE
hasPublishedDocs: false
script:
- "extension type ET(String i) { foo(covariant String child) {} }"
ExtraneousModifierInPrimaryConstructor:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "Can't have modifier '#lexeme' in a primary constructor."
correctionMessage: "Try removing '#lexeme'."
analyzerCode: ParserErrorCode.EXTRANEOUS_MODIFIER_IN_PRIMARY_CONSTRUCTOR
hasPublishedDocs: false
script:
- "extension type ET(covariant String i) { }"
FinalAndCovariant:
type: syntacticError
parameters: none
problemMessage: "Members can't be declared to be both 'final' and 'covariant'."
correctionMessage: "Try removing either the 'final' or 'covariant' keyword."
analyzerCode: ParserErrorCode.FINAL_AND_COVARIANT
hasPublishedDocs: false
script:
- "class C { covariant final f = 5; }"
- "class C { final covariant f = 5; }"
exampleAllowOtherCodes: true
FinalAndCovariantLateWithInitializer:
type: syntacticError
parameters: none
problemMessage: "Members marked 'late' with an initializer can't be declared to be both 'final' and 'covariant'."
correctionMessage: "Try removing either the 'final' or 'covariant' keyword, or removing the initializer."
analyzerCode: ParserErrorCode.FINAL_AND_COVARIANT_LATE_WITH_INITIALIZER
hasPublishedDocs: false
# Weak and strong doesn't matter in this instance.
script:
- "class C { covariant late final f = 5; }"
FinalAndVar:
type: syntacticError
parameters: none
problemMessage: "Members can't be declared to be both 'final' and 'var'."
correctionMessage: "Try removing the keyword 'var'."
analyzerCode: ParserErrorCode.FINAL_AND_VAR
hasPublishedDocs: false
script:
- "class C { final var x = 5; }"
- "class C { var final x = 5; }"
StaticConstructor:
type: syntacticError
parameters: none
problemMessage: "Constructors can't be static."
correctionMessage: "Try removing the keyword 'static'."
analyzerCode: ParserErrorCode.STATIC_CONSTRUCTOR
hasPublishedDocs: false
script:
- "class C { static C() {} }"
- "class C { static C.m() {} }"
GetterConstructor:
type: syntacticError
parameters: none
problemMessage: "Constructors can't be a getter."
correctionMessage: "Try removing 'get'."
analyzerCode: ParserErrorCode.GETTER_CONSTRUCTOR
hasPublishedDocs: false
script:
- "class C { get C.m() {} }"
SetterConstructor:
type: syntacticError
parameters: none
problemMessage: "Constructors can't be a setter."
correctionMessage: "Try removing 'set'."
analyzerCode: ParserErrorCode.SETTER_CONSTRUCTOR
hasPublishedDocs: false
script:
- "class C { set C.m(x) {} }"
StaticOperator:
type: syntacticError
parameters: none
problemMessage: "Operators can't be static."
correctionMessage: "Try removing the keyword 'static'."
analyzerCode: ParserErrorCode.STATIC_OPERATOR
hasPublishedDocs: false
script:
- "class C { static operator +(int x) => x + 1; }"
BreakOutsideOfLoop:
type: syntacticError
parameters: none
problemMessage: "A break statement can't be used outside of a loop or switch statement."
correctionMessage: "Try removing the break statement."
analyzerCode: ParserErrorCode.BREAK_OUTSIDE_OF_LOOP
hasPublishedDocs: false
script:
- "main() { break; }"
ContinueOutsideOfLoop:
type: syntacticError
parameters: none
problemMessage: "A continue statement can't be used outside of a loop or switch statement."
correctionMessage: "Try removing the continue statement."
analyzerCode: ParserErrorCode.CONTINUE_OUTSIDE_OF_LOOP
hasPublishedDocs: false
script:
- "main() { continue; }"
exampleAllowOtherCodes: true
ContinueWithoutLabelInCase:
type: syntacticError
parameters: none
problemMessage: "A continue statement in a switch statement must have a label as a target."
correctionMessage: "Try adding a label associated with one of the case clauses to the continue statement."
analyzerCode: ParserErrorCode.CONTINUE_WITHOUT_LABEL_IN_CASE
hasPublishedDocs: false
script:
- "main(List<String> x) { switch (x) {case 1: continue;} }"
DuplicateLabelInSwitchStatement:
type: syntacticError
parameters:
Name name: undocumented
problemMessage: "The label '#name' was already used in this switch statement."
correctionMessage: "Try choosing a different name for this label."
analyzerCode: ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT
hasPublishedDocs: false
comment: |-
Parameters:
0: the label that was duplicated
statement:
- "switch (0) {l1: case 0: break; l1: case 1: break;}"
InitializedVariableInForEach:
type: syntacticError
parameters: none
problemMessage: "The loop variable in a for-each loop can't be initialized."
correctionMessage: "Try removing the initializer, or using a different kind of loop."
analyzerCode: ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH
hasPublishedDocs: false
statement:
- "for (int a = 0 in <int>[10]) {}"
InvalidAwaitFor:
type: syntacticError
parameters: none
problemMessage: "The keyword 'await' isn't allowed for a normal 'for' statement."
correctionMessage: "Try removing the keyword, or use a for-each statement."
analyzerCode: ParserErrorCode.INVALID_AWAIT_IN_FOR
hasPublishedDocs: false
script:
- "f() async {await for (int i = 0; i < 5; i++) {}}"
VoidWithTypeArguments:
type: syntacticError
parameters: none
problemMessage: "Type 'void' can't have type arguments."
correctionMessage: "Try removing the type arguments."
analyzerCode: ParserErrorCode.VOID_WITH_TYPE_ARGUMENTS
hasPublishedDocs: false
script:
- "void<int> f() {}"
# TODO(danrubel): Review where this error is generated and consider generating
# FieldInitializedOutsideDeclaringClass instead of this in some situations.
InvalidInitializer:
type: syntacticError
parameters: none
problemMessage: "Not a valid initializer."
correctionMessage: "To initialize a field, use the syntax 'name = value'."
analyzerCode: ParserErrorCode.INVALID_INITIALIZER
hasPublishedDocs: false
script: |
class A {
int a = 0;
}
class B extends A {
B() : super.a = 42;
}
exampleAllowOtherCodes: true
FieldInitializedOutsideDeclaringClass:
type: syntacticError
parameters: none
problemMessage: "A field can only be initialized in its declaring class"
correctionMessage: "Try passing a value into the superclass constructor, or moving the initialization into the constructor body."
analyzerCode: ParserErrorCode.FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS
hasPublishedDocs: false
script:
- "class A { int a; } class C extends A { C() : super.a = 42; }"
exampleAllowOtherCodes: true
StackOverflow:
type: syntacticError
parameters: none
problemMessage: "The file has too many nested expressions or statements."
correctionMessage: "Try simplifying the code."
analyzerCode: ParserErrorCode.STACK_OVERFLOW
hasPublishedDocs: false
InvalidHexEscape:
type: syntacticError
parameters: none
problemMessage: "An escape sequence starting with '\\x' must be followed by 2 hexadecimal digits."
analyzerCode: ParserErrorCode.INVALID_HEX_ESCAPE
hasPublishedDocs: false
expression:
- "'\\x0'"
- "'\\x0y'"
InvalidUnicodeEscapeUStarted:
type: syntacticError
parameters: none
problemMessage: "An escape sequence starting with '\\u' must be followed by 4 hexadecimal digits or from 1 to 6 digits between '{' and '}'."
analyzerCode: ParserErrorCode.INVALID_UNICODE_ESCAPE_U_STARTED
hasPublishedDocs: false
expression:
- "'\\u'"
InvalidUnicodeEscapeUNoBracket:
type: syntacticError
parameters: none
problemMessage: "An escape sequence starting with '\\u' must be followed by 4 hexadecimal digits."
analyzerCode: ParserErrorCode.INVALID_UNICODE_ESCAPE_U_NO_BRACKET
hasPublishedDocs: false
expression:
- "'\\u0F'"
InvalidUnicodeEscapeUBracket:
type: syntacticError
parameters: none
problemMessage: "An escape sequence starting with '\\u{' must be followed by 1 to 6 hexadecimal digits followed by a '}'."
analyzerCode: ParserErrorCode.INVALID_UNICODE_ESCAPE_U_BRACKET
hasPublishedDocs: false
expression:
- "'\\u{'"
- "'\\u{03'"
- "'\\u{0Z}'"
- "'\\u{0000003}'"
InvalidEscapeStarted:
type: syntacticError
parameters: none
problemMessage: "The string '\\' can't stand alone."
correctionMessage: "Try adding another backslash (\\) to escape the '\\'."
analyzerCode: ParserErrorCode.INVALID_UNICODE_ESCAPE_STARTED
hasPublishedDocs: false
exampleAllowOtherCodes: true
expression:
- |
print('Hello, World!\
');
UnexpectedTokens:
type: syntacticError
parameters: none
problemMessage: "Unexpected tokens."
analyzerCode: ParserErrorCode.UNEXPECTED_TOKENS
hasPublishedDocs: false
script: "enum E w Foo { v; }"
LiteralWithClassAndNew:
type: syntacticError
parameters:
String string: undocumented
Token lexeme: undocumented
problemMessage: "A #string literal can't be prefixed by 'new #lexeme'."
correctionMessage: "Try removing 'new' and '#lexeme'"
analyzerCode: ParserErrorCode.LITERAL_WITH_CLASS_AND_NEW
hasPublishedDocs: false
script:
- "var x = new Map{};"
- "var x = new Set{};"
- "var x = new List[];"
- "var x = new Map{1: 2};"
- "var x = new Set{1};"
- "var x = new List[1];"
LiteralWithClass:
type: syntacticError
parameters:
String string: undocumented
Token lexeme: undocumented
problemMessage: "A #string literal can't be prefixed by '#lexeme'."
correctionMessage: "Try removing '#lexeme'"
analyzerCode: ParserErrorCode.LITERAL_WITH_CLASS
hasPublishedDocs: false
script:
- "var x = Map{};"
- "var x = Set{};"
- "var x = List<String>[];"
- "var x = Map{1: 2};"
- "var x = Set{1};"
- "var x = List<int>[1];"
- "var x = const Map{};"
- "var x = const Set{};"
- "var x = const List[];"
- "var x = const Map{1: 2};"
- "var x = const Set{1};"
- "var x = const List[1];"
LiteralWithNew:
type: syntacticError
parameters: none
problemMessage: "A literal can't be prefixed by 'new'."
correctionMessage: "Try removing 'new'"
analyzerCode: ParserErrorCode.LITERAL_WITH_NEW
hasPublishedDocs: false
script:
- "var x = new <String, String>{};"
- "var x = new <String>{};"
- "var x = new {};"
- "var x = new [];"
- "var x = new <String, String>{'a': 'b'};"
- "var x = new <String>{'a'};"
- "var x = new {'a': 'b'};"
- "var x = new {'a'};"
- "var x = new ['a'];"
OnlyTry:
type: syntacticError
parameters: none
problemMessage: "A try block must be followed by an 'on', 'catch', or 'finally' clause."
correctionMessage: "Try adding either a catch or finally clause, or remove the try statement."
analyzerCode: ParserErrorCode.MISSING_CATCH_OR_FINALLY
hasPublishedDocs: false
statement: "try {}"
TypeAfterVar:
type: syntacticError
parameters: none
problemMessage: "Variables can't be declared using both 'var' and a type name."
correctionMessage: "Try removing 'var.'"
analyzerCode: ParserErrorCode.VAR_AND_TYPE
hasPublishedDocs: false
script:
- "var String foo; main(){}"
exampleAllowOtherCodes: true
CatchSyntax:
type: syntacticError
parameters: none
problemMessage: "'catch' must be followed by '(identifier)' or '(identifier, identifier)'."
correctionMessage: "No types are needed, the first is given by 'on', the second is always 'StackTrace'."
analyzerCode: ParserErrorCode.CATCH_SYNTAX
hasPublishedDocs: false
statement:
- "try {} catch {}"
- "try {} catch () {}"
- "try {} catch (e,) {}"
CatchSyntaxExtraParameters:
type: syntacticError
parameters: none
problemMessage: "'catch' must be followed by '(identifier)' or '(identifier, identifier)'."
correctionMessage: "No types are needed, the first is given by 'on', the second is always 'StackTrace'."
analyzerCode: ParserErrorCode.CATCH_SYNTAX_EXTRA_PARAMETERS
hasPublishedDocs: false
statement:
- "try {} catch (e, s, x) {}"
SuperNullAware:
type: syntacticError
parameters: none
problemMessage: "The operator '?.' cannot be used with 'super' because 'super' cannot be null."
correctionMessage: "Try replacing '?.' with '.'"
analyzerCode: ParserErrorCode.INVALID_OPERATOR_QUESTIONMARK_PERIOD_FOR_SUPER
hasPublishedDocs: false
script: |
class Super {
Super.named();
}
class Class extends Super {
Class() : super?.named();
}
exampleAllowOtherCodes: true
NullAwareCascadeOutOfOrder:
type: syntacticError
parameters: none
problemMessage: "The '?..' cascade operator must be first in the cascade sequence."
correctionMessage: "Try moving the '?..' operator to be the first cascade operator in the sequence."
analyzerCode: ParserErrorCode.NULL_AWARE_CASCADE_OUT_OF_ORDER
hasPublishedDocs: false
script: |
void foo(int? x) {
x
..hashCode
?..isEven;
}
exampleAllowOtherCodes: true
MetadataTypeArguments:
type: syntacticError
parameters: none
problemMessage: "An annotation can't use type arguments."
analyzerCode: ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS
hasPublishedDocs: false
script: |
// @dart=2.12
class C<T> {
const C();
}
@C<int>() // Error
void foo() {}
MetadataTypeArgumentsUninstantiated:
type: syntacticError
parameters: none
problemMessage: "An annotation with type arguments must be followed by an argument list."
analyzerCode: ParserErrorCode.ANNOTATION_WITH_TYPE_ARGUMENTS_UNINSTANTIATED
hasPublishedDocs: false
script:
- "@deprecated<int> class C {}"
MetadataSpaceBeforeParenthesis:
type: syntacticError
parameters: none
problemMessage: "Annotations can't have spaces or comments before the parenthesis."
correctionMessage: Remove any spaces or comments before the parenthesis.
analyzerCode: ParserErrorCode.ANNOTATION_SPACE_BEFORE_PARENTHESIS
hasPublishedDocs: false
script:
- >-
class Foo<T> {
const Foo();
}
@Foo<int> () var bar;
- >-
class Foo {
const Foo();
}
@Foo () class Bar {}
ConstructorWithReturnType:
type: syntacticError
parameters: none
problemMessage: "Constructors can't have a return type."
correctionMessage: "Try removing the return type."
analyzerCode: ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE
hasPublishedDocs: false
script:
- "class C { int C() {} }"
- "class C { void C.m() {} }"
ConstructorWithTypeParameters:
type: syntacticError
parameters: none
problemMessage: "Constructors can't have type parameters."
analyzerCode: ParserErrorCode.TYPE_PARAMETER_ON_CONSTRUCTOR
hasPublishedDocs: false
correctionMessage: "Try removing the type parameters."
script:
- >-
class C { C<T>() {} }
- >-
class C { C.foo<T>() {} }
- >-
class C {
factory C<T>() => new C.internal();
C.internal();
}
- >-
class C {
factory C.foo<T>() => new C.internal();
C.internal();
}
ConstructorWithTypeArguments:
type: syntacticError
parameters: none
problemMessage: "A constructor invocation can't have type arguments after the constructor name."
correctionMessage: "Try removing the type arguments or placing them after the class name."
analyzerCode: ParserErrorCode.CONSTRUCTOR_WITH_TYPE_ARGUMENTS
hasPublishedDocs: false
script:
- "class C<X> { C.foo(); } bar() { new C.foo<int>(); }"
- "class C<X> { C.foo(); } bar() { C.foo<int>(); }"
ConstructorWithWrongName:
type: syntacticError
parameters: none
problemMessage: "The name of a constructor must match the name of the enclosing class."
analyzerCode: ParserErrorCode.INVALID_CONSTRUCTOR_NAME
hasPublishedDocs: false
script:
- >-
class A { B.foo() {} }
- >-
class A {
factory B() => new A.internal();
A.internal();
}
- >-
class A {
factory B.foo() => new A.internal();
A.internal();
}
FieldInitializerOutsideConstructor:
type: compileTimeError
parameters: none
problemMessage: "Field formal parameters can only be used in a constructor."
correctionMessage: "Try removing 'this.'."
analyzerCode: CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
hasPublishedDocs: true
documentation: |-
#### Description
The analyzer produces this diagnostic when an initializing formal
parameter is used in the parameter list for anything other than a
constructor.
#### Example
The following code produces this diagnostic because the initializing
formal parameter `this.x` is being used in the method `m`:
```dart
class A {
int x = 0;
m([[!this.x!] = 0]) {}
}
```
#### Common fixes
Replace the initializing formal parameter with a normal parameter and
assign the field within the body of the method:
```dart
class A {
int x = 0;
m([int x = 0]) {
this.x = x;
}
}
```
script:
- "class C { void m(this.x); }"
exampleAllowOtherCodes: true
NativeClauseShouldBeAnnotation:
type: syntacticError
parameters: none
problemMessage: "Native clause in this form is deprecated."
correctionMessage: "Try removing this native clause and adding @native() or @native('native-name') before the declaration."
analyzerCode: ParserErrorCode.NATIVE_CLAUSE_SHOULD_BE_ANNOTATION
hasPublishedDocs: false
MissingPrefixInDeferredImport:
type: syntacticError
parameters: none
problemMessage: "Deferred imports should have a prefix."
correctionMessage: "Try adding a prefix to the import by adding an 'as' clause."
analyzerCode: ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT
hasPublishedDocs: false
script:
main.dart: |
import 'lib.dart' deferred;
lib.dart: ""
DeferredAfterPrefix:
type: syntacticError
parameters: none
problemMessage: "The deferred keyword should come immediately before the prefix ('as' clause)."
correctionMessage: "Try moving the deferred keyword before the prefix."
analyzerCode: ParserErrorCode.DEFERRED_AFTER_PREFIX
hasPublishedDocs: false
script:
main.dart: |
import "lib.dart" as foo deferred;
lib.dart: ""
DuplicateDeferred:
type: syntacticError
parameters: none
problemMessage: "An import directive can only have one 'deferred' keyword."
correctionMessage: "Try removing all but one 'deferred' keyword."
analyzerCode: ParserErrorCode.DUPLICATE_DEFERRED
hasPublishedDocs: false
script:
main.dart: |
import "lib.dart" deferred as foo deferred;
lib.dart: ""
DuplicatePrefix:
type: syntacticError
parameters: none
problemMessage: "An import directive can only have one prefix ('as' clause)."
correctionMessage: "Try removing all but one prefix."
analyzerCode: ParserErrorCode.DUPLICATE_PREFIX
hasPublishedDocs: false
script:
main.dart: |
import "lib.dart" as foo as bar;
lib.dart: ""
PrefixAfterCombinator:
type: syntacticError
parameters: none
problemMessage: "The prefix ('as' clause) should come before any show/hide combinators."
correctionMessage: "Try moving the prefix before the combinators."
analyzerCode: ParserErrorCode.PREFIX_AFTER_COMBINATOR
hasPublishedDocs: false
script:
main.dart: |
import "lib.dart" show Foo hide Foo as Foo;
lib.dart: ""
MixinDeclaresConstructor:
type: syntacticError
parameters: none
problemMessage: "Mixins can't declare constructors."
analyzerCode: ParserErrorCode.MIXIN_DECLARES_CONSTRUCTOR
hasPublishedDocs: false
script: |
mixin M {
const M();
}
ExtensionDeclaresAbstractMember:
type: syntacticError
parameters: none
problemMessage: "Extensions can't declare abstract members."
correctionMessage: "Try providing an implementation for the member."
script: |
extension E on int {
void method();
}
analyzerCode: ParserErrorCode.EXTENSION_DECLARES_ABSTRACT_MEMBER
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when an abstract declaration is
declared in an extension. Extensions can declare only concrete members.
#### Example
The following code produces this diagnostic because the method `a` doesn't
have a body:
```dart
extension E on String {
int [!a!]();
}
```
#### Common fixes
Either provide an implementation for the member or remove it.
hasPublishedDocs: true
ExtensionDeclaresConstructor:
type: syntacticError
parameters: none
problemMessage: "Extensions can't declare constructors."
correctionMessage: "Try removing the constructor declaration."
script: |
extension E on int {
E();
}
analyzerCode: ParserErrorCode.EXTENSION_DECLARES_CONSTRUCTOR
comment: No parameters.
documentation: |-
#### Description
The analyzer produces this diagnostic when a constructor declaration is
found in an extension. It isn't valid to define a constructor because
extensions aren't classes, and it isn't possible to create an instance of
an extension.
#### Example
The following code produces this diagnostic because there is a constructor
declaration in `E`:
```dart
extension E on String {
[!E!]() : super();
}
```
#### Common fixes
Remove the constructor or replace it with a static method.
hasPublishedDocs: true
ExtensionAugmentationHasOnClause:
type: syntacticError
parameters: none
problemMessage: "Extension augmentations can't have 'on' clauses."
correctionMessage: "Try removing the 'on' clause."
analyzerCode: ParserErrorCode.EXTENSION_AUGMENTATION_HAS_ON_CLAUSE
hasPublishedDocs: false
script: |
augment extension E on int {}
comment: No parameters.
AnnotationOnTypeArgument:
type: syntacticError
parameters: none
problemMessage: "Type arguments can't have annotations because they aren't declarations."
analyzerCode: ParserErrorCode.ANNOTATION_ON_TYPE_ARGUMENT
hasPublishedDocs: false
script:
- "class A<E> {} class C { m() => new A<@Object() C>(); }"
ExternalClass:
type: syntacticError
parameters: none
problemMessage: "Classes can't be declared to be 'external'."
correctionMessage: "Try removing the keyword 'external'."
analyzerCode: ParserErrorCode.EXTERNAL_CLASS
hasPublishedDocs: false
script:
- "external class C {}"
ExternalEnum:
type: syntacticError
parameters: none
problemMessage: "Enums can't be declared to be 'external'."
correctionMessage: "Try removing the keyword 'external'."
analyzerCode: ParserErrorCode.EXTERNAL_ENUM
hasPublishedDocs: false
script:
- "external enum E {ONE}"
ExternalMethodWithBody:
type: syntacticError
parameters: none
problemMessage: "An external or native method can't have a body."
analyzerCode: ParserErrorCode.EXTERNAL_METHOD_WITH_BODY
hasPublishedDocs: false
script:
- "class C {external foo() {}}"
- "class C {foo() native {}}"
- "class C {foo() native 'bar' {}}"
ExternalConstructorWithInitializer:
type: syntacticError
parameters: none
problemMessage: "An external constructor can't have any initializers."
analyzerCode: ParserErrorCode.EXTERNAL_CONSTRUCTOR_WITH_INITIALIZER
hasPublishedDocs: false
script:
- "class C { int? x; external C() : x = 1; }"
- "class C { int? x; external C.foo() : x = 1; }"
ExternalTypedef:
type: syntacticError
parameters: none
problemMessage: "Typedefs can't be declared to be 'external'."
correctionMessage: "Try removing the keyword 'external'."
analyzerCode: ParserErrorCode.EXTERNAL_TYPEDEF
hasPublishedDocs: false
script:
- "external typedef F();"
OperatorWithTypeParameters:
type: syntacticError
parameters: none
problemMessage: "Types parameters aren't allowed when defining an operator."
correctionMessage: "Try removing the type parameters."
analyzerCode: ParserErrorCode.TYPE_PARAMETER_ON_OPERATOR
hasPublishedDocs: false
comment: |-
7.1.1 Operators: Type parameters are not syntactically supported on an
operator.
script:
- "class C { operator []<T>(T t) => null; }"
LibraryDirectiveNotFirst:
type: syntacticError
parameters: none
problemMessage: "The library directive must appear before all other directives."
correctionMessage: "Try moving the library directive before any other directives."
analyzerCode: ParserErrorCode.LIBRARY_DIRECTIVE_NOT_FIRST
hasPublishedDocs: false
script:
- "class Foo{} library l;"
- "import 'x.dart'; library l;"
- "part 'a.dart'; library l;"
exampleAllowOtherCodes: true
ImportAfterPart:
type: syntacticError
parameters: none
problemMessage: "Import directives must precede part directives."
correctionMessage: "Try moving the import directives before the part directives."
analyzerCode: ParserErrorCode.IMPORT_DIRECTIVE_AFTER_PART_DIRECTIVE
hasPublishedDocs: false
script:
- "part 'foo.dart'; import 'bar.dart';"
exampleAllowOtherCodes: true
ExportAfterPart:
type: syntacticError
parameters: none
problemMessage: "Export directives must precede part directives."
correctionMessage: "Try moving the export directives before the part directives."
analyzerCode: ParserErrorCode.EXPORT_DIRECTIVE_AFTER_PART_DIRECTIVE
hasPublishedDocs: false
exampleAllowOtherCodes: true
script:
- "part 'foo.dart'; export 'bar.dart';"
DirectiveAfterDeclaration:
type: syntacticError
parameters: none
problemMessage: "Directives must appear before any declarations."
correctionMessage: "Try moving the directive before any declarations."
analyzerCode: ParserErrorCode.DIRECTIVE_AFTER_DECLARATION
hasPublishedDocs: false
script:
- main.dart: |
class foo { }
import 'bar.dart';
bar.dart: ""
- main.dart: |
class foo { }
export 'bar.dart';
bar.dart: ""
PartOfTwice:
type: syntacticError
parameters: none
problemMessage: "Only one part-of directive may be declared in a file."
correctionMessage: "Try removing all but one of the part-of directives."
analyzerCode: ParserErrorCode.MULTIPLE_PART_OF_DIRECTIVES
hasPublishedDocs: false
script:
- main.dart: |
part "part.dart";
main() {}
other.dart: ""
part.dart: |
part of "other.dart";
part of "main.dart";
- main.dart: |
part of "lib.dart";
part of "lib.dart";
main() {}
lib.dart: |
part "main.dart";
- main.dart: |
part "part.dart";
part.dart: |
part of "main.dart";
part of "main.dart";
FactoryTopLevelDeclaration:
type: syntacticError
parameters: none
problemMessage: "Top-level declarations can't be declared to be 'factory'."
correctionMessage: "Try removing the keyword 'factory'."
analyzerCode: ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION
hasPublishedDocs: false
script:
- "factory class C {}"
RedirectionInNonFactory:
type: syntacticError
parameters: none
problemMessage: "Only factory constructor can specify '=' redirection."
correctionMessage: "Try making this a factory constructor, or remove the redirection."
analyzerCode: ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR
hasPublishedDocs: false
script:
- "class C { C() = D; }"
exampleAllowOtherCodes: true
TopLevelOperator:
type: syntacticError
parameters: none
problemMessage: "Operators must be declared within a class."
correctionMessage: "Try removing the operator, moving it to a class, or converting it to be a function."
analyzerCode: ParserErrorCode.TOP_LEVEL_OPERATOR
hasPublishedDocs: false
script:
- "operator +(bool x, bool y) => x | y;"
- "bool operator +(bool x, bool y) => x | y;"
- "void operator +(bool x, bool y) => x | y;"
TypeArgumentsOnTypeVariable:
type: syntacticError
parameters:
Name name: undocumented
problemMessage: "Can't use type arguments with type variable '#name'."
correctionMessage: "Try removing the type arguments."
analyzerCode: ParserErrorCode.TYPE_ARGUMENTS_ON_TYPE_VARIABLE
hasPublishedDocs: false
script:
- "void method<S>(S<int> a) {}"
# Use this message when a duplicated declaration is introduced. For example:
#
# class C {} // First declaration (related information points here).
# class C {} // Duplicated declaration (error here).
# main() {
# new C(); // Use of duplicated declaration.
# }
#
# We follow the convention from C that a definition is the unique element that
# provides the implementation of a name, and a declaration may not be unique
# (for example, forward declaration). Using this terminology, one could argue
# that a method that is abstract or external is a declaration, not a
# definition. Similarly, imported names are declarations, not
# definitions. Consequently, it is more convenient to use the word
# "declaration" instead of "definition" as the former implies less.
MemberWithSameNameAsClass:
type: syntacticError
parameters: none
problemMessage: "A class member can't have the same name as the enclosing class."
correctionMessage: "Try renaming the member."
analyzerCode: ParserErrorCode.MEMBER_WITH_CLASS_NAME
hasPublishedDocs: false
script:
- "class C { get C {} }"
- "class C { get C => 42; }"
- "class C { set C(x) {} }"
- "class C { set C(x) => 42; }"
- "class C { int? C; }"
- "class C { int? A, B, C, D, E; }"
MissingOperatorKeyword:
type: syntacticError
parameters: none
problemMessage: "Operator declarations must be preceded by the keyword 'operator'."
correctionMessage: "Try adding the keyword 'operator'."
analyzerCode: ParserErrorCode.MISSING_KEYWORD_OPERATOR
hasPublishedDocs: false
script:
- "class C { +(x) {} }"
InvalidOperator:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: "The string '#lexeme' isn't a user-definable operator."
analyzerCode: ParserErrorCode.INVALID_OPERATOR
hasPublishedDocs: false
comment: |-
Parameters:
0: the operator that is invalid
script:
- "class C { void operator %=(x) {} }"
InvalidSuperInInitializer:
type: syntacticError
parameters: none
problemMessage: "Can only use 'super' in an initializer for calling the superclass constructor (e.g. 'super()' or 'super.namedConstructor()')"
analyzerCode: ParserErrorCode.INVALID_SUPER_IN_INITIALIZER
hasPublishedDocs: false
InvalidThisInInitializer:
type: syntacticError
parameters: none
problemMessage: "Can only use 'this' in an initializer for field initialization (e.g. 'this.x = something') and constructor redirection (e.g. 'this()' or 'this.namedConstructor())"
analyzerCode: ParserErrorCode.INVALID_THIS_IN_INITIALIZER
hasPublishedDocs: false
SwitchHasCaseAfterDefault:
type: syntacticError
parameters: none
problemMessage: "The default case should be the last case in a switch statement."
correctionMessage: "Try moving the default case after the other case clauses."
analyzerCode: ParserErrorCode.SWITCH_HAS_CASE_AFTER_DEFAULT_CASE
hasPublishedDocs: false
script:
- "class C { foo(int a) {switch (a) {default: return 0; case 1: return 1;}} }"
SwitchHasMultipleDefaults:
type: syntacticError
parameters: none
problemMessage: "The 'default' case can only be declared once."
correctionMessage: "Try removing all but one default case."
analyzerCode: ParserErrorCode.SWITCH_HAS_MULTIPLE_DEFAULT_CASES
hasPublishedDocs: false
script:
- "class C { foo(int a) {switch (a) {default: return 0; default: return 1;}} }"
ExpectedAnInitializer:
type: syntacticError
parameters: none
problemMessage: "Expected an initializer."
analyzerCode: ParserErrorCode.MISSING_INITIALIZER
hasPublishedDocs: false
script:
- "class C { C() : {} }"
MissingAssignmentInInitializer:
type: syntacticError
parameters: none
problemMessage: "Expected an assignment after the field name."
correctionMessage: "To initialize a field, use the syntax 'name = value'."
analyzerCode: ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER
hasPublishedDocs: false
script:
- "class C { C() : x(3) {} }"
exampleAllowOtherCodes: true
RedirectingConstructorWithBody:
type: syntacticError
parameters: none
problemMessage: "Redirecting constructors can't have a body."
correctionMessage: "Try removing the body, or not making this a redirecting constructor."
analyzerCode: ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY
hasPublishedDocs: false
script:
- "class C { C() : this.x() {} }"
exampleAllowOtherCodes: true
IllegalAssignmentToNonAssignable:
type: syntacticError
parameters: none
problemMessage: "Illegal assignment to non-assignable expression."
analyzerCode: ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE
hasPublishedDocs: false
script:
- "main(){ f()++; }"
MissingAssignableSelector:
type: syntacticError
parameters: none
problemMessage: "Missing selector such as '.identifier' or '[0]'."
correctionMessage: "Try adding a selector."
analyzerCode: ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR
hasPublishedDocs: false
script:
- "main(){ ++f(); }"
ColonInPlaceOfIn:
type: syntacticError
parameters: none
problemMessage: "For-in loops use 'in' rather than a colon."
correctionMessage: "Try replacing the colon with the keyword 'in'."
analyzerCode: ParserErrorCode.COLON_IN_PLACE_OF_IN
hasPublishedDocs: false
script: |
void foo() {
for(var x : []) {}
}
BinaryOperatorWrittenOut:
type: syntacticError
parameters:
String string: undocumented
String string2: undocumented
problemMessage: "Binary operator '#string' is written as '#string2' instead of the written out word."
correctionMessage: "Try replacing '#string' with '#string2'."
analyzerCode: ParserErrorCode.BINARY_OPERATOR_WRITTEN_OUT
hasPublishedDocs: false
script: |
int foo(int x, int y) => x xor y;
ExternalFactoryRedirection:
type: syntacticError
parameters: none
problemMessage: "A redirecting factory can't be external."
correctionMessage: "Try removing the 'external' modifier."
analyzerCode: ParserErrorCode.EXTERNAL_FACTORY_REDIRECTION
hasPublishedDocs: false
script: |
class Foo {
Foo._(int i);
external factory Foo.x(int i) = Foo._;
}
MultipleVarianceModifiers:
type: syntacticError
parameters: none
problemMessage: "Each type parameter can have at most one variance modifier."
correctionMessage: "Use at most one of the 'in', 'out', or 'inout' modifiers."
analyzerCode: ParserErrorCode.MULTIPLE_VARIANCE_MODIFIERS
hasPublishedDocs: false
experiments: variance
script: |
class C<in out X> {}
BaseEnum:
type: syntacticError
parameters: none
problemMessage: "Enums can't be declared to be 'base'."
correctionMessage: "Try removing the keyword 'base'."
analyzerCode: ParserErrorCode.BASE_ENUM
hasPublishedDocs: false
script:
- "base enum E { v }"
FinalEnum:
type: syntacticError
parameters: none
problemMessage: "Enums can't be declared to be 'final'."
correctionMessage: "Try removing the keyword 'final'."
analyzerCode: ParserErrorCode.FINAL_ENUM
hasPublishedDocs: false
script:
- "final enum E { v }"
InterfaceEnum:
type: syntacticError
parameters: none
problemMessage: "Enums can't be declared to be 'interface'."
correctionMessage: "Try removing the keyword 'interface'."
analyzerCode: ParserErrorCode.INTERFACE_ENUM
hasPublishedDocs: false
script:
- "interface enum E { v }"
SealedEnum:
type: syntacticError
parameters: none
problemMessage: "Enums can't be declared to be 'sealed'."
correctionMessage: "Try removing the keyword 'sealed'."
analyzerCode: ParserErrorCode.SEALED_ENUM
hasPublishedDocs: false
script:
- "sealed enum E { v }"
FinalMixin:
type: syntacticError
parameters: none
problemMessage: "A mixin can't be declared 'final'."
correctionMessage: "Try removing the 'final' keyword."
analyzerCode: ParserErrorCode.FINAL_MIXIN
hasPublishedDocs: false
script:
- "final mixin M {}"
InterfaceMixin:
type: syntacticError
parameters: none
problemMessage: "A mixin can't be declared 'interface'."
correctionMessage: "Try removing the 'interface' keyword."
analyzerCode: ParserErrorCode.INTERFACE_MIXIN
hasPublishedDocs: false
script:
- "interface mixin M {}"
SealedMixin:
type: syntacticError
parameters: none
problemMessage: "A mixin can't be declared 'sealed'."
correctionMessage: "Try removing the 'sealed' keyword."
analyzerCode: ParserErrorCode.SEALED_MIXIN
hasPublishedDocs: false
script:
- "sealed mixin M {}"
FinalMixinClass:
type: syntacticError
parameters: none
problemMessage: "A mixin class can't be declared 'final'."
correctionMessage: "Try removing the 'final' keyword."
analyzerCode: ParserErrorCode.FINAL_MIXIN_CLASS
hasPublishedDocs: false
script:
- "final mixin class C {}"
InterfaceMixinClass:
type: syntacticError
parameters: none
problemMessage: "A mixin class can't be declared 'interface'."
correctionMessage: "Try removing the 'interface' keyword."
analyzerCode: ParserErrorCode.INTERFACE_MIXIN_CLASS
hasPublishedDocs: false
script:
- "interface mixin class C {}"
SealedMixinClass:
type: syntacticError
parameters: none
problemMessage: "A mixin class can't be declared 'sealed'."
correctionMessage: "Try removing the 'sealed' keyword."
analyzerCode: ParserErrorCode.SEALED_MIXIN_CLASS
hasPublishedDocs: false
script:
- "sealed mixin class C {}"
InvalidConstantPatternNegation:
type: syntacticError
parameters: none
problemMessage: "Only negation of a numeric literal is supported as a constant pattern."
correctionMessage: "Try wrapping the expression in 'const ( ... )'."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_PATTERN_NEGATION
hasPublishedDocs: false
script: |
method(x) {
const y = 5;
if (x case -y) {}
}
InvalidConstantPatternUnary:
type: syntacticError
parameters:
Name name: undocumented
problemMessage: "The unary operator #name is not supported as a constant pattern."
correctionMessage: "Try wrapping the expression in 'const ( ... )'."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_PATTERN_UNARY
hasPublishedDocs: false
script: |
method(x) {
const y = false;
if (x case !y) {}
}
InvalidConstantPatternDuplicateConst:
type: syntacticError
parameters: none
problemMessage: "Duplicate 'const' keyword in constant expression."
correctionMessage: "Try removing one of the 'const' keywords."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_PATTERN_DUPLICATE_CONST
hasPublishedDocs: false
script: |
method(x) {
if (x case const const []) {}
}
InvalidConstantPatternEmptyRecordLiteral:
type: syntacticError
parameters: none
problemMessage: "The empty record literal is not supported as a constant pattern."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_PATTERN_EMPTY_RECORD_LITERAL
hasPublishedDocs: false
script: |
method(x) {
if (x case const ()) {}
}
InvalidConstantPatternGeneric:
type: syntacticError
parameters: none
problemMessage: "This expression is not supported as a constant pattern."
correctionMessage: "Try wrapping the expression in 'const ( ... )'."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_PATTERN_GENERIC
hasPublishedDocs: false
script: |
method(x) {
if (x case List<int>) {}
}
InvalidConstantPatternConstPrefix:
type: syntacticError
parameters: none
problemMessage: "The expression can't be prefixed by 'const' to form a constant pattern."
correctionMessage: "Try wrapping the expression in 'const ( ... )' instead."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_CONST_PREFIX
hasPublishedDocs: false
script: |
method(x) {
if (x case const 1) {}
}
InvalidConstantPatternBinary:
type: syntacticError
parameters:
Name name: undocumented
problemMessage: "The binary operator #name is not supported as a constant pattern."
correctionMessage: "Try wrapping the expression in 'const ( ... )'."
analyzerCode: ParserErrorCode.INVALID_CONSTANT_PATTERN_BINARY
hasPublishedDocs: false
script: |
method(x) {
if (x case 1 + 2) {}
}
PatternAssignmentDeclaresVariable:
type: syntacticError
parameters:
Name name: undocumented
problemMessage: "Variable '#name' can't be declared in a pattern assignment."
correctionMessage: "Try using a preexisting variable or changing the assignment to a pattern variable declaration."
analyzerCode: ParserErrorCode.PATTERN_ASSIGNMENT_DECLARES_VARIABLE
hasPublishedDocs: false
script: |
method(x) {
var y;
[y, var z] = x;
}
VariablePatternKeywordInDeclarationContext:
type: syntacticError
parameters: none
problemMessage: Variable patterns in declaration context can't specify 'var' or 'final' keyword.
correctionMessage: Try removing the keyword.
analyzerCode: ParserErrorCode.VARIABLE_PATTERN_KEYWORD_IN_DECLARATION_CONTEXT
comment: No parameters.
hasPublishedDocs: true
script: |
void f((int, int) r) {
var (var x, y) = r;
print(x + y);
}
documentation: |-
#### Description
The analyzer produces this diagnostic when a variable pattern is used
within a declaration context.
#### Example
The following code produces this diagnostic because the variable patterns
in the record pattern are in a declaration context:
```dart
void f((int, int) r) {
var ([!var!] x, y) = r;
print(x + y);
}
```
#### Common fixes
Remove the `var` or `final` keyword(s) within the variable pattern:
```dart
void f((int, int) r) {
var (x, y) = r;
print(x + y);
}
```
IllegalPatternVariableName:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: The variable declared by a variable pattern can't be named '#lexeme'.
correctionMessage: Choose a different name.
analyzerCode: ParserErrorCode.ILLEGAL_PATTERN_VARIABLE_NAME
hasPublishedDocs: false
comment: |-
Parameters:
0: the illegal name
script: |
void f(x) {
switch (x) {
case var when:
}
}
IllegalPatternAssignmentVariableName:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: A variable assigned by a pattern assignment can't be named '#lexeme'.
correctionMessage: Choose a different name.
analyzerCode: ParserErrorCode.ILLEGAL_PATTERN_ASSIGNMENT_VARIABLE_NAME
hasPublishedDocs: false
comment: |-
Parameters:
0: the illegal name
script: |
void f(x) {
dynamic when;
(when) = x;
}
IllegalPatternIdentifierName:
type: syntacticError
parameters:
Token lexeme: undocumented
problemMessage: A pattern can't refer to an identifier named '#lexeme'.
correctionMessage: Match the identifier using '== #lexeme'.
analyzerCode: ParserErrorCode.ILLEGAL_PATTERN_IDENTIFIER_NAME
hasPublishedDocs: false
comment: |-
Parameters:
0: the illegal name
script: |
void f(x) {
const when = 0;
switch (x) {
case when:
}
}
InvalidInsideUnaryPattern:
type: syntacticError
parameters: none
problemMessage: This pattern cannot appear inside a unary pattern (cast pattern, null check pattern, or null assert pattern) without parentheses.
correctionMessage: Try combining into a single pattern if possible, or enclose the inner pattern in parentheses.
analyzerCode: ParserErrorCode.INVALID_INSIDE_UNARY_PATTERN
hasPublishedDocs: false
comment: No parameters.
script: |
void f(x) {
if (x case _ as int as num) {}
}
LatePatternVariableDeclaration:
type: syntacticError
parameters: none
problemMessage: A pattern variable declaration may not use the `late` keyword.
correctionMessage: Try removing the keyword `late`.
analyzerCode: ParserErrorCode.LATE_PATTERN_VARIABLE_DECLARATION
hasPublishedDocs: false
comment: No parameters.
script: |
void f(x) {
late var (y, z) = x;
}
PatternVariableDeclarationOutsideFunctionOrMethod:
type: syntacticError
parameters: none
problemMessage: A pattern variable declaration may not appear outside a function or method.
correctionMessage: Try declaring ordinary variables and assigning from within a function or method.
analyzerCode: ParserErrorCode.PATTERN_VARIABLE_DECLARATION_OUTSIDE_FUNCTION_OR_METHOD
hasPublishedDocs: false
comment: No parameters.
script: |
class C {
var (a, b) = (0, 1);
}
DefaultInSwitchExpression:
type: syntacticError
parameters: none
problemMessage: A switch expression may not use the `default` keyword.
correctionMessage: Try replacing `default` with `_`.
analyzerCode: ParserErrorCode.DEFAULT_IN_SWITCH_EXPRESSION
hasPublishedDocs: false
comment: No parameters.
script: |
void f(x) => switch (x) {
1 => 'one',
default => 'other'
};
MissingPrimaryConstructor:
type: syntacticError
parameters: none
problemMessage: "An extension type declaration must have a primary constructor declaration."
correctionMessage: "Try adding a primary constructor to the extension type declaration."
analyzerCode: ParserErrorCode.MISSING_PRIMARY_CONSTRUCTOR
hasPublishedDocs: false
script: |
extension type E {}
MissingPrimaryConstructorParameters:
type: syntacticError
parameters: none
problemMessage: "A primary constructor declaration must have formal parameters."
correctionMessage: "Try adding formal parameters after the primary constructor name."
analyzerCode: ParserErrorCode.MISSING_PRIMARY_CONSTRUCTOR_PARAMETERS
hasPublishedDocs: false
script: |
extension type E.name {}
ExtensionTypeExtends:
type: syntacticError
parameters: none
problemMessage: "An extension type declaration can't have an 'extends' clause."
correctionMessage: "Try removing the 'extends' clause or replacing the 'extends' with 'implements'."
analyzerCode: ParserErrorCode.EXTENSION_TYPE_EXTENDS
hasPublishedDocs: false
script: |
extension type F(int i) {}
extension type E(int i) extends F {}
ExtensionTypeWith:
type: syntacticError
parameters: none
problemMessage: "An extension type declaration can't have a 'with' clause."
correctionMessage: "Try removing the 'with' clause or replacing the 'with' with 'implements'."
analyzerCode: ParserErrorCode.EXTENSION_TYPE_WITH
hasPublishedDocs: false
script: |
extension type F(int i) {}
extension type E(int i) with F {}
ConstWithoutPrimaryConstructor:
type: syntacticError
parameters: none
problemMessage: "'const' can only be used together with a primary constructor declaration."
correctionMessage: "Try removing the 'const' keyword or adding a primary constructor declaration."
analyzerCode: ParserErrorCode.CONST_WITHOUT_PRIMARY_CONSTRUCTOR
hasPublishedDocs: false
script: |
class const C {}
NewConstructorQualifiedName:
type: syntacticError
parameters: none
problemMessage: "Constructors declared with the 'new' keyword can't have qualified names."
correctionMessage: "Try removing the class name prefix from the qualified name or removing the 'new' keyword."
analyzerCode: ParserErrorCode.NEW_CONSTRUCTOR_QUALIFIED_NAME
hasPublishedDocs: false
experiments: declaring-constructors
script: |
class C {
new C.named();
}
NewConstructorNewName:
type: syntacticError
parameters: none
problemMessage: "Constructors declared with the 'new' keyword can't be named 'new'."
correctionMessage: "Try removing the second 'new' or changing it to a different name."
analyzerCode: ParserErrorCode.NEW_CONSTRUCTOR_NEW_NAME
hasPublishedDocs: false
experiments: declaring-constructors
script: |
class C {
new new();
}
FactoryConstructorNewName:
type: syntacticError
parameters: none
problemMessage: "Factory constructors can't be named 'new'."
correctionMessage: "Try removing the 'new' keyword or changing it to a different name."
analyzerCode: ParserErrorCode.FACTORY_CONSTRUCTOR_NEW_NAME
hasPublishedDocs: false
experiments: declaring-constructors
script: |
class C {
factory new() => throw '';
}