Skip to content

Analyzer doesn't detect duplicate named parameter in constructor #26296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
skybrian opened this issue Apr 19, 2016 · 6 comments
Closed

Analyzer doesn't detect duplicate named parameter in constructor #26296

skybrian opened this issue Apr 19, 2016 · 6 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).

Comments

@skybrian
Copy link

For example, in DartPad, no diagnostics appear for this case:

class Foo {
  final bool bar;
  Foo({this.bar, bar});
}
@skybrian skybrian added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 19, 2016
@bwilkerson
Copy link
Member

Is it suppose to? According to the specification:

Using an initializing formal this.id in a formal parameter list does not introduce a formal parameter name into the scope of the constructor.

I think this is working as expected.

@skybrian
Copy link
Author

Here's a more complete example:

class Foo {
  final bool bar;
  final bool baz;
  Foo({this.bar, bar}) : baz = bar;
  toString() => "Foo($bar, $baz)";
}

main() {
  print(new Foo(bar: true));
}

It works in Dartpad (the parameter gets assigned to both fields), but the Dart VM doesn't allow it:

$ dart ~/tmp/test.dart
'file:///Users/skybrian/tmp/test.dart': error: line 4 pos 18: duplicate formal parameter 'bar'
Foo({this.bar, bar}) : baz = bar;

If it's not an analyzer bug, perhaps it's a VM bug?

@bwilkerson bwilkerson reopened this Apr 19, 2016
@bwilkerson
Copy link
Member

We need clarification on the specification.

@bwilkerson bwilkerson added area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). and removed legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Apr 19, 2016
@eernstg
Copy link
Member

eernstg commented Jul 11, 2016

The feature described in #26655 (access to initializing formals) implies that initializing formals will be added to the formal parameter scope for resolution in the initializer list, and that feature has been scheduled for inclusion in the language. The conflict described in this issue will be in line with the spec after the spec has been updated. So it should be possible to resolve this issue as part of the same process where #26655 is implemented.

@eernstg
Copy link
Member

eernstg commented Nov 30, 2016

I believe this issue is now obsolete (the original example does create a name clash which is a compile-time error, and the analyzer does detect it, just like the VM always did, even before the spec said so ;-).

Closing. Please reopen if you think there is still an issue.

@eernstg eernstg closed this as completed Nov 30, 2016
@skybrian
Copy link
Author

skybrian commented Dec 2, 2016

Verified that analysis server detects it. There is still no error in Dartpad, though. I guess Dartpad is so out of date that we can't rely on it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language).
Projects
None yet
Development

No branches or pull requests

3 participants