Skip to content

Should static extension allow generative redirecting constructors? #4558

@leafpetersen

Description

@leafpetersen

We currently propose to allow static extensions to declare generative redirecting constructors. However, because constructors on static extensions may return instances with more specific types than their static type, we currently propose to forbid such a constructor from being used in another redirecting constructor call, or a super call. In comments here, @stereotype441 makes the following point:

If we're not going to allow a constructor declared in an extension to be used as a super-initializer, or as the target of a redirecting generative constructor, then what's the point of allowing an extension to declare a redirecting generative constructor at all? Is it just so that an extension can declare a const constructor?

If so, I'm not sure that carries its weight. I would be more inclined to prohibit an extension from declaring a redirecting generative constructor, and if at some future point we decide that we want extensions to be able to declare const constructors, we do so by a more general feature that allows any factory constructor with a potentially constant body to be declared const.

As currently specified, generative constructors in static extensions are only supported for the const use case. Should we instead disallow them for now and consider the more general solution?

cc @dart-lang/language-team

Metadata

Metadata

Assignees

No one assigned

    Labels

    static-extensionsIssues about the static-extensions feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions