Beef
Beef copied to clipboard
Access to deleted object not identified
In the code below, dlg should have triggered the error "Attempt to access deleted object", since this was deleted at that point.
public static class Program
{
class TestDeleted
{
public bool test;
public delegate bool() GetDlg()
{
return new () => { return test; };
}
}
public static void Main()
{
let obj = new TestDeleted();
let dlg = obj.GetDlg();
delete obj;
Console.WriteLine(dlg()); // No error!
Console.WriteLine(obj.test); // Attempt to access deleted object
}
}
Tested with: https://github.com/beefytech/Beef/commit/1c7b7df25fd8f72b25f29bec13d99221c9f4b268
The fundamental problem is that the delegate doesn't know if the captured this belongs to a struct or an object at invocation time.
Hm- though I suppose if we store the Type of the captured this then we could actually have the debugger properly show the this value instead of just the type-erased void*...
At least in debug mode - and let release be the smaller and faster type-erased version...