-
Notifications
You must be signed in to change notification settings - Fork 772
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
Extension method on byref can mutate an immutable value #5355
Comments
Note that this can also be done with reference types: open System
open System.Runtime.CompilerServices
[<Extension>]
type Ext() =
[<Extension>]
static member inline Change(s: byref<string>) = s <-"Hoopty"
let f() =
let s = "beef"
printfn "%s" s
let dtRef = &s
dtRef.Change()
printfn "%s" s
dtRef.Change()
printfn "%s" s
dtRef.Change()
printfn "%s" s
[<EntryPoint>]
let main argv =
f()
0 // return an integer exit code Gives
|
Highly aware of this. Looking into it. |
I guess this is the same or similar problem as the Please do not disallow byref access to immutable/read-only structures, as it used for performance critical work (if I remember correctly the readonly/immutable byref changed to |
@zpodlovics it looks like it is similar, but those are referring to instance members. I think I know what's happening in the compiler, but it needs more investigation. Basically on calls like this we lose information that it was a byref or a inref; it only compares the destination type of the byref. |
I have a fix for this coming soon. |
Resolved. |
Consider the following F# code:
Executing with ctrl-f5:
The text was updated successfully, but these errors were encountered: