Specifying a default value for a member of a struct #4744
Labels
a:language-slint
Compiler for the .slint language (mO,bF)
duplicate
This issue or pull request already exists
enhancement
New feature or request
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:
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 toflat
as it is the first element in the enum. My preference however would be that it should beneutral
.Of course, I could resolve this by re-ordering my enum, but it feels as though there should be some flexibility here?
The text was updated successfully, but these errors were encountered: