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

It is not an error to have a constructor with the same name as the class #5940

Closed
peter-ahe-google opened this issue Oct 16, 2012 · 7 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue 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

@peter-ahe-google
Copy link
Contributor

The specification (as of October 8, 2012) says:

"A constructor name always begins with the name of its immediately enclosing class, and may optionally be followed by a dot and an identifier id. It is a compile-time error if id is the name of a member declared in the immediately enclosing class. It is a compile-time error if the name of a constructor is not a constructor name."

This means that this is not an error:

class C {
  C.C();
}

main() {
  print(new C.C());
}

I think this should be an error.

@gbracha
Copy link
Contributor

gbracha commented Nov 7, 2012

Why? There is no ambiguity here.


Added this to the M2 milestone.
Added Accepted label.

@peter-ahe-google
Copy link
Contributor Author

There is no ambiguity here:

class C {
  static void foo() {}
  C.foo() {}
}

But we reject this because we don't want to have multiple namespaces. I think this situation is analogous.

@gbracha
Copy link
Contributor

gbracha commented Nov 12, 2012

So the basic issue here is a desire to keep the namespace model as simple as possible. This is admirable. One would like to say that there is a single namespace for the class, with instance and static members and constructors in it. However, this is not actually true. Given a constructor C.foo, foo is not in scope in any sense: one cannot write new foo() for example (and one cannot write just foo in any other context inside the class either).

I feel this is just too complex.

@gbracha
Copy link
Contributor

gbracha commented Nov 28, 2012

Removed this from the M2 milestone.
Added this to the Later milestone.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@peter-ahe-google peter-ahe-google added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed accepted labels Feb 29, 2016
@munificent
Copy link
Member

This would be a breaking change at this point, so it's not likely to happen.

@munificent munificent added the closed-not-planned Closed as we don't intend to take action on the reported issue label Dec 19, 2016
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). closed-not-planned Closed as we don't intend to take action on the reported issue 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