dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.08k stars 1.56k forks source link

Multiple diagnostic messages emitted for duplicate definition #26788

Open eernstg opened 8 years ago

eernstg commented 8 years ago

With reference to the common issue #18361, and following the recommendation in tests/compiler/dart2js/message_kind_helper.dart to create an issue on this situation:

Duplicate declarations of initializing formal parameters give rise to multiple diagnostic messages with dart2js --initializing-formal-access. For instance, consider the following program:

class C {
  var x;
  C(this.x, this.x);
}

main() {
  print(new C(2, 2));
}

The program causes the following messages:

Error: Field 'x' is initialized more than once.
Info: 'x' was already initialized here.
008.dart:6:18:
Error: Duplicate definition of 'x'.
Try to rename or remove this definition.
  C(this.x, this.x);
                 ^
008.dart:6:10:
Info: Existing definition of 'x'.
  C(this.x, this.x);
         ^
Error: Compilation failed.

Emitting messages about just one of the problems caused by the duplication would be less confusing for developers. No information would be lost since there is only one root problem: the duplication.

Note that the effect of having option --initializing-formal-access will be the regular semantics soon, i.e., the issue will then exist also for runs with no options.

eernstg commented 7 years ago

Turns out the problem still exists.