blob: 293cb6d6ef16a603e43093cbf94f55364defa75f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
{$MODE OBJFPC}
program test;
type
TBaseClass = class
function PrintSelf(): TBaseClass; inline; // has to be inline for the bug to manifest
end;
TSubClass = class(TBaseClass)
end;
function TBaseClass.PrintSelf(): TBaseClass; inline;
begin
Writeln(PtrUInt(Self));
Result := nil;
Writeln(PtrUInt(Self)); // prints 0!
if not assigned(self) then
halt(1);
end;
procedure NoOp(var Dummy: TBaseClass);
begin
end;
var
Instance, Variable: TBaseClass;
res: longint;
begin
Instance := TSubClass.Create();
Variable := nil;
NoOp(Variable); // this call is important for the bug to manifest
Variable := Instance;
// object being invoked has to be cast to a different type for the bug to manifest
// return value has to be assigned to the variable being used as "self"
Variable := TSubClass(Variable).PrintSelf();
Instance.Free();
end.
|