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.28k stars 1.58k forks source link

Clarify constructor name restrictions. #18672

Closed lrhn closed 5 years ago

lrhn commented 10 years ago

The specification (section "Constructors") says that it's a compile time error to have a constructor Foo.id if "id" is declared as a member in the class. I think the specification needs to be e

Is a constructor a declared member of the class? It seems it isn't, since other parts of the specification says "members or constructors".

If it is a member, what is its name? Is it "Foo.id" or "id"? What is the name of the default constructor: "Foo" or ""?

What prevents having two constructors named "Foo.id"? If constructors are not members, or the name of "Foo.id" isn't "id", the text above does not prevent it.

Also, if the name of the constructor "Foo" is "", then there is nothing preventing the constructor name "Foo.Foo"? Is this correct? It seems the VM disallows "Foo.Foo", but dart2js and the analyzer allows it.

gbracha commented 10 years ago

I think some further explanation is needed. That said:

Constructors are not members.

Section 10.6 states:

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.

Section 6.1 says:

It is a compile-time error if there is more than one entity with the same name declared in the same scope.

So duplicates of Foo.id are illegal. Foo.Foo is also legal, though perhaps it should not be.


Set owner to @gbracha. Added Accepted label.

eernstg commented 6 years ago

No milestone now: This will not block Dart 2.

The clarification will still need to be performed, hence the issue remains open.

eernstg commented 5 years ago

Closing: I believe this has been resolved, particularly in the section 'Class Member Conflicts' in dartLangSpect.tex.