-
Notifications
You must be signed in to change notification settings - Fork 213
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
Comments
Do you mean you want |
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 |
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? |
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 |
for example:
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?
The text was updated successfully, but these errors were encountered: