Skip to content

Analyzer does not report repeated field initialization #61940

@lrhn

Description

@lrhn

Example:

class C {
  int x;
  C.n1(this.x) : x = x; // INVALID
  C.n2(int x) : x = x, x = x; // INVALID
}
void main() {}

The specification states:

It is a compile-time error if more than one initializer corresponding
to a given instance variable appears in $k$'s initializer list.
It is a compile-time error if $k$'s initializer list contains
an initializer for a variable that is initialized by means of
an initializing formal of $k$.

so both C.n1 and C.n2 should be errors.

The analyzer fails to report C.n1 and C.n2 as errors, the CFE reports:

invalidreinit.dart:3:20: Error: 'x' was already initialized by this constructor.
  C.n1(this.x) : x = x; // INVALID
                   ^
invalidreinit.dart:4:26: Error: 'x' was already initialized by this constructor.
  C.n2(int x) : x = x, x = x; // INVALID
                         ^

Metadata

Metadata

Assignees

Labels

area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions