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

Explicit Name For Default Constructor #1477

Closed
fweth opened this issue Feb 25, 2021 · 2 comments
Closed

Explicit Name For Default Constructor #1477

fweth opened this issue Feb 25, 2021 · 2 comments
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@fweth
Copy link

fweth commented Feb 25, 2021

There is this ambiguity between types and default constructors, so [Foo(a)] is interpreted as 'call the default constructor of Foo with argument a' but [a].map(Foo) gives an error because Foo is interpreted as type, so we have to type [a].map((x)=>Foo(x)). It would be cool to have a way to explicitly call the default constructor, like [a].map(Foo.Foo) or [a].map(Foo.constructor).

@fweth fweth added the feature Proposed language feature that solves one or more problems label Feb 25, 2021
@eernstg eernstg added the state-duplicate This issue or pull request already exists label Feb 25, 2021
@eernstg
Copy link
Member

eernstg commented Feb 25, 2021

This is essentially a proposal to support tearing off constructors, hence a duplicate of #216. (Please vote up that one if you wish to support this feature!)

You mention using Foo as an expression, and that does indeed evaluate to an instance of Type that reifies the type Foo. However, it is also an error to use Foo.named as an expression in the following context:

class Foo {
  Foo.named();
}

void main() => Foo.named; // Error.

So we'd need to support tearing off a constructor as a first step, and then we'd need some syntax to denote the constructor whose name is the class name; one proposal given in #216 is Foo.new.

@eernstg eernstg closed this as completed Feb 25, 2021
@fweth
Copy link
Author

fweth commented Feb 25, 2021

Ah, sorry, I didn't find that one. Thanks for the link!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants