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

DefaultValue attribute should require 'mutable' when used in classes and records #484

Open
cloudRoutine opened this issue Oct 12, 2016 · 0 comments
Labels

Comments

@cloudRoutine
Copy link
Owner

Idea 9679206: DefaultValue attribute should require 'mutable' when used in classes and records

Status : planned
Submitted by Don Syme on 9/8/2015 12:00:00 AM
1 votes

For structs, adding the DefaultValue attribute to a val declaration (a field) results in a check that the field is mutable, since it doesn't make sense to use an immutable field which only ever has the default value.
[]
type S() =
[] val x : C
AssemblyReader.fs(4304,23): error FS0880: Uninitialized 'val' fields must be mutable and marked with the '[]' attribute. Consider using a 'let' binding instead of a 'val' field.
For some reason, this condition is only checked for fields declared in structs. We should likewise give a warning for records and classes:
type C() =
[] val x : C
and
type R = { [] x : C; y : int }

Response

** by fslang-admin on 9/8/2015 12:00:00 AM **

Approved for inclusion in a future release of F#.
Please consider contributing to F# by providing an implementation, with adequate testing. The code to be adjusted is around here: https://github.com/fsharp/fsharp/blob/212c3359bf6d83e30c12e53fd2ef283d3257b328/src/fsharp/PostInferenceChecks.fs#L1422. For some reason, the code is only activated for struct/enum type definitions, but it should also apply to record and class type definitions.
Don Syme, F# Language Evolution
Archived Uservoice Comments

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

No branches or pull requests

1 participant