Skip to content

Named constructors have separate namespace #3040

Closed

Description

@peter-ahe-google

Consider this class:

class Foo {
  Foo.bar();
  static bar() => new Foo.bar();
}

This allows you to write:

var a = Foo.bar();
var b = new Foo.bar();

This doesn't seem to be in the spirit of what we set out to achieve when it comes to avoiding multiple name spaces.

Activity

  1. gbracha commented on May 14, 2012

    @gbracha
    Contributor

    I agree this is undesirable. Nevertheless, I'm tentatively categorizing it as an enhancement rather than a defect (a defect is an inconsistency/error in the spec). I agree we should try and fix it.


    Set owner to @gbracha.
    Removed Type-Defect label.
    Added Type-Enhancement, Accepted labels.

  2. gbracha commented on May 29, 2012

    @gbracha
    Contributor

    Added this to the M1 milestone.

  3. gbracha commented on Jul 4, 2012

    @gbracha
    Contributor

    Section 7.6 now reads:

    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.

    I think this resolves the issue in the spirit of a single namespace.


    Added Done label.

  4. DartBot commented on Aug 31, 2012

    @DartBot

    This comment was originally written by @mhausner


    What about this case:

    class A {
      foo() {...}
    }

    class B extends A {
      B.foo() {...}
    }

    The above text would allow this, but what is the semantics? Would the instance method foo, which is inherited by B, get overridden by the named constructor B.foo ?

  5. gbracha commented on Aug 31, 2012

    @gbracha
    Contributor

    In this case, nothing has changed from previous behavior. Constructors never override anything and are not inherited. So A's foo() and the constructor in B do not interact.

  6. added this to the M1 milestone on Aug 31, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).type-enhancementA request for a change that isn't a bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions