-
Notifications
You must be signed in to change notification settings - Fork 830
Auto-generated getters on structs get readonly attribute #13413
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
Conversation
b9484c2 to
41035ab
Compare
a19aa4a to
738184c
Compare
… struct-getters-readonly
src/Compiler/CodeGen/IlxGen.fs
Outdated
| let ilMethName = "get_" + ilPropName | ||
| let access = ComputeMemberAccess isPropHidden | ||
| yield mkLdfldMethodDef (ilMethName, access, isStatic, ilThisTy, ilFieldName, ilPropType) | ||
| let isStruct = tcref.IsFSharpStructOrEnumTycon && not tcref.IsEnumTycon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why the check is implemented this way?
At least in the IL code something else seems to be analyzed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed like the easiest way to do it here. I'm definitely open to other suggestions. Maybe we should add IsFShartStructTycon. Or maybe just use IsFSharpStructOrEnumTycon because enum will never reach this place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving it up to you, just voting for consistent approach if applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can do it like in ILTypeDef, but I did find another way which might be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, I'm definitely okay with the current approach
#8962
So far it works for records and anonymous records.
Would like to get it to work for regular structs too but they seem to use a different mechanism for generating their getters.The following case is not covered, because that would require analyzing user supplied getter code for side-effects.
It does work for when the getter is auto-generated: