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

Optional shared keyword for public actor methods with caller? #4794

Open
rvanasa opened this issue Dec 3, 2024 · 2 comments
Open

Optional shared keyword for public actor methods with caller? #4794

rvanasa opened this issue Dec 3, 2024 · 2 comments

Comments

@rvanasa
Copy link
Contributor

rvanasa commented Dec 3, 2024

For simplicity and consistency, it could make sense for the shared keyword to always be optional for public actor methods. This would increase readability and reduce confusion about when the keyword is needed, e.g. when adding a caller to an existing method.

For example, instead of the following:

public shared ({ caller }) func abc() { ... };

It could make sense to allow:

public ({ caller }) func abc() { ... };

This is an observation from reviewing the Motoko training samples. Is there anything from a technical standpoint that prevents us from making this change?

@crusso
Copy link
Contributor

crusso commented Dec 4, 2024

Might be worth trying but my hunch is that this ambiguous with the special case of

public when is just
i.e.
public

Though that is a arguably useless (since wouldn't declare anything to make public) and could be factored out of the grammar.

The relevant bit of the grammar describing these modifiers is:

<shared_pat_opt> ::=

'shared' ? <pat_plain>?
<pat_plain>?

@rvanasa
Copy link
Contributor Author

rvanasa commented Dec 4, 2024

That's a good point. I remember coming across this a few years ago.

Example snippet (runnable):

module {
  let msg = 123;
  public (msg)
}

For anyone reading this, note that the module in the above example does not actually include any public fields despite the public keyword.

Since the current grammar allows statements such as public 5 (but seemingly only at the end of an object/module/class), any usage of this is likely unintentional, so we may want to factor this out either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants