Skip to content
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

Unexpected change in analysis results when removing extends Object #45959

Closed
bwilkerson opened this issue May 9, 2021 · 7 comments
Closed

Unexpected change in analysis results when removing extends Object #45959

bwilkerson opened this issue May 9, 2021 · 7 comments
Assignees
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@bwilkerson
Copy link
Member

Given a file a.dart containing

class A {
  void _foo() {}
}

class B {
  void _foo() {}
}

and another file containing

import 'a.dart';

class C extends Object with A, B {}

the analyzer produces the following expected diagnostic

error: The private name '_foo', defined by 'B', conflicts with the same name defined by 'A'. (private_collision_in_mixin_application)

But if the extends clause is removed:

import 'a.dart';

class C extends Object with A, B {}

then the diagnostic is not reported.

Is this a bug in the analyzer, or is this expected behavior?

@bwilkerson bwilkerson added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label May 9, 2021
@lrhn
Copy link
Member

lrhn commented May 9, 2021

If there is a difference in behavior, then it's a bug.
A class declaration of class C with A, B {} is completely equivalent to on of class C extends Object with A, B {}.

I'll admit I can't remember the special cases around mixin-application and private names (#28809 mentions it, but I can't find anything in the spec).
Whichever is right, both programs should behave the same.

@bwilkerson
Copy link
Member Author

@eernstg For clarification on the spec.

@jcollins-g jcollins-g added the P2 A bug or feature request we're likely to work on label May 10, 2021
@scheglov scheglov self-assigned this May 10, 2021
@scheglov scheglov added the analyzer-spec Issues with the analyzer's implementation of the language spec label May 10, 2021
@scheglov
Copy link
Contributor

I can reproduce it.

@scheglov
Copy link
Contributor

@jcollins-g jcollins-g added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label May 10, 2021
@eernstg
Copy link
Member

eernstg commented May 10, 2021

Searching the language specification and other documents (but this is from 2017, so it should be in the language specification by now), I also don't see anything about this error. But it should definitely never make a difference whether extends Object is written explicitly or implied because there is no extends clause.

I proposed a specification of the private collision error in dart-lang/language#1626.

I can see that we have tests, in particular pkg/analyzer/test/src/diagnostics/private_collision_in_mixin_application_test.dart, and they are testing the case where the colliding private declarations occur directly in the superclass and mixin, so we might not have tests covering the situation where the mixin member collides with some other concrete member that the superclass has (but doesn't declare), in which case the superclass may also be declared in some other library.

@scheglov
Copy link
Contributor

It was requested as #28809

@eernstg
Copy link
Member

eernstg commented May 10, 2021

Yes, I did mention #28809 in the PR dart-lang/language#1626, and this comment implies, if C is intended to be an error, that there should be a conflict on get _x from 'lib.dart' even though the superclass B is not declared in 'lib.dart'.

dart-bot pushed a commit that referenced this issue May 10, 2021
…cit Object supertype.

Bug: #45959
Change-Id: I064c70a1bf869fae09c2f56271a212b910d853ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/199062
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants