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

[extension type] Automatic completion type #3518

Closed
medz opened this issue Dec 15, 2023 · 2 comments
Closed

[extension type] Automatic completion type #3518

medz opened this issue Dec 15, 2023 · 2 comments
Labels
feature Proposed language feature that solves one or more problems

Comments

@medz
Copy link

medz commented Dec 15, 2023

basic

The extension type will be released soon in version 3.3, and it can currently be constructed via as:

extension type Test(String message) {
     void echo() => print(message);
}

void echo(Test message) => message.echo();

void main() => echo("Hello, Dart" as Test);

I have a new idea, why can't we ignore as T and implement automatic construction? For example:

void main() => echo("Hello, Auto factory");

Constructor and factory selection

Beyond that, I think a lot of it is already clear what type of parameter position is required, and we can ignore the type flag and just use . to select static members of the type:

enum E { one, two }

void echo(E select) => print('Selected ${E}.${selecte.name}');

void main() {
     echo(.one); // Full is `E.one`
     echo(.two);
}

The same is true for the construction entry selection of extension type/class:

extension type E(String message) {
     factory E.pre(String message) => '[PRE] $message';
     // OR
     // factory E.pre(String message) => E('[PRE] $message');
}

void echo(E demo) => print(demo.message);

void main() {
     echo('One');
     echo(.pre('Two'));
}

Why do this?

First of all, this should be a syntactic sugar (🍬). The reason is that I have a type that has several factory functions, and the type is wrapped into a List.

Without it, the code:

final List<PathConponent> paths = [
     PathConponent('a'),
     PathCompoinent.param('b'),
     // ... and more
];

It's much simpler when you have autocomplete types:

final List<PathConponent> paths = ['a', .params('b')];
@medz medz added the feature Proposed language feature that solves one or more problems label Dec 15, 2023
@medz
Copy link
Author

medz commented Dec 19, 2023

@munificent
Copy link
Member

I believe this is a duplicate of #3614.

@munificent munificent closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
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
Projects
None yet
Development

No branches or pull requests

2 participants