Last active
September 10, 2023 09:13
-
-
Save habib-sadullaev/3524c2c113ae81a15af15fb355f302cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type IRef = | |
abstract member Ref: unit -> byref<int> | |
type C() = | |
let mutable num = 10 | |
member _.Get() = num | |
member _.Ref() = &num | |
interface IRef with | |
member this.Ref() = &this.Ref() | |
let inline func (c: C) = | |
&c.Ref() | |
let inline func'<'a when 'a :> IRef> (c: 'a) = | |
&c.Ref() | |
let inline func'' (c: ^c when ^c: (member Ref: unit -> byref<int>)) = // should compile | |
&c.Ref() //compile time error FS3236: Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address. | |
let inline func''' (c) = // should compile | |
&(^c: (member Ref: unit -> byref<int>) c) //compile time error FS3236: Cannot take the address of the value returned from the expression. Assign the returned value to a let-bound value before taking the address. | |
let inline func'''' (c) : byref<int> = // should return `int` instead of `byref<int>` according to https://github.com/fsharp/fslang-design/blob/main/FSharp-4.5/FS-1053-span.md#implicit-dereference-of-return-byrefs | |
(^c: (member Ref: unit -> byref<int>) c) //but error on calling - error FS0001: This expression was expected to have type | |
// 'byref<int>' | |
// but here has type | |
// 'int' | |
let g () = | |
let c = C() | |
let mutable x = &func'''' c | |
x <- 1000 | |
c.Get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment