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

Principal in static module variables - non-static expression in library or moduleMotoko(M0014) #4754

Open
infu opened this issue Nov 4, 2024 · 4 comments

Comments

@infu
Copy link

infu commented Nov 4, 2024

Minor hindrance worth mentioning. Not something that we can't get around.

module {
public let default_id = Principal.fromText("lxzze-o7777-77777-aaaaa-cai");

results in
non-static expression in library or moduleMotoko(M0014)

There is no way to put a principal inside a module's static variables

Perhaps something like this would work, similar to how Blob works

module {
public let default_id = "lxzze-o7777-77777-aaaaa-cai":Principal
@crusso
Copy link
Contributor

crusso commented Nov 4, 2024

Yeah, that's annoying. You could declare a constant function instead.

@ggreif
Copy link
Contributor

ggreif commented Nov 4, 2024

What about let default_actor : actor {} = actor "lxzze-o7777-77777-aaaaa-cai"; and then turn that into a Principal at the usage site?

@infu
Copy link
Author

infu commented Nov 4, 2024

nice, both options work better than what I tried - putting opt and later trapping if it's not there

@ggreif
Copy link
Contributor

ggreif commented Nov 5, 2024

@crusso maybe we can mark certain functions/prims as static-preserving, and as such extend the set of allowed values in modules?

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

3 participants