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

Specifying a default value for a member of a struct #4744

Closed
tronical opened this issue Mar 4, 2024 Discussed in #4738 · 1 comment
Closed

Specifying a default value for a member of a struct #4744

tronical opened this issue Mar 4, 2024 Discussed in #4738 · 1 comment
Labels
a:language-slint Compiler for the .slint language (mO,bF) duplicate This issue or pull request already exists enhancement New feature or request

Comments

@tronical
Copy link
Member

tronical commented Mar 4, 2024

Discussed in #4738

Originally posted by mitchgrout March 3, 2024
As I understand, if a member of a struct is not explicitly initialized, it will be set to its default value. However, as far as I can tell there is no way to set a new default value for a member, as the following is illegal:

export struct Test {
  value: int = 42
}

My take is that the default value for some types, including user-defined types, might not always be desirable. For example, I might want to have export enum Accidental { flat, neutral, sharp }. However, if I used this within a struct and forgot to explicitly initialize the field, then it would default to flat as it is the first element in the enum. My preference however would be that it should be neutral.

Of course, I could resolve this by re-ordering my enum, but it feels as though there should be some flexibility here?

@tronical tronical added enhancement New feature or request a:language-slint Compiler for the .slint language (mO,bF) labels Mar 4, 2024
@ogoffart
Copy link
Member

ogoffart commented Mar 4, 2024

Closing as duplicate of #2936

@ogoffart ogoffart closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
@ogoffart ogoffart added the duplicate This issue or pull request already exists label Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-slint Compiler for the .slint language (mO,bF) duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants