open System.Runtime.InteropServices
open System.Reflection
[<Struct>]
[<StructLayout(LayoutKind.Sequential)>]
type x =
val mutable t : uint32
[<Struct>]
[<StructLayout(LayoutKind.Sequential)>]
type y =
val mutable t : bool
let mutable p = x(t=1u)
p :> y (* error *)
let mutable ptr = Marshal.AllocHGlobal(sizeof<x>);
Marshal.StructureToPtr(p,ptr,false)
let y = Marshal.PtrToStructure(ptr,typeof<y>) :?> y
y.t (* = true *)