Skip to content

How to constrain arguments cannot be anonymous function at compile time #1798

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

Closed
Silentdoer opened this issue Aug 12, 2021 · 5 comments
Closed
Labels
request Requests to resolve a particular developer problem

Comments

@Silentdoer
Copy link

Silentdoer commented Aug 12, 2021

for example:

void submit(Function task) {
}

Task is not allowed to be an anonymous function, because it does not have a static lifecycle, so it cannot be sent to other isolates, So how do we prevent users from using anonymous functions at compile time?

@Silentdoer Silentdoer added the request Requests to resolve a particular developer problem label Aug 12, 2021
@Levi-Lesches
Copy link

Do you mean you want task to be a compile-time constant? That would be #1684. I suggest you write there explaining why you would need this because IIRC they're having a hard time justifying the need for it.

@Silentdoer
Copy link
Author

Silentdoer commented Aug 12, 2021

What I mean is that user cannot pass a closure to the task(such as (a) => 8), because closure can not as message send to other isolate to exec

@Levi-Lesches
Copy link

Right, essentially this:

class Task {const Task(void Function() callback);}
void temp() { }

const Task a = Task(temp);  // works, because we use an existing function
const Task b = Task(() => print("Hello"));  // closures aren't constant

@Silentdoer
Copy link
Author

Right, essentially this:

class Task {const Task(void Function() callback);}
void temp() { }

const Task a = Task(temp);  // works, because we use an existing function
const Task b = Task(() => print("Hello"));  // closures aren't constant

Can detection only be used for construction methods?

@Levi-Lesches
Copy link

Sorry, what do you mean by construction methods? Class constructors? You can't specify that a constructor can only accept const parameters, but if you try creating a const object (using a const constructor), you'd only be able to pass in a const parameter.

class Task {const Task(void Function() callback);}
void temp() { }

const Task a = Task(temp);  // works, because we use an existing function
final Task b = Task(() => print("Hello"));  // works because b isn't const 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem
Projects
None yet
Development

No branches or pull requests

2 participants