inline type helper gives wrong result in with
Summary
Combining type helpers, with, and inline gives wrong data
System Information
- Operating system: Linux, Android
- Processor architecture: ARM
- Compiler version: 3.3.1 [2022/06/27]
It does not happen with 3.2 fixes. I do not have a more recent 3.3.1 installed
Example Project
program Project1;
{$Mode objfpc}{$H+}{$ModeSwitch advancedrecords}
uses sysutils;
type
TWrappedData = record
public
data: pointer;
function clone: TWrappedData;
end;
function TWrappedData.clone: TWrappedData;
begin
result.data := data;
end;
type TWrappedDataHelper = record helper for TWrappedData
function getData: pointer; inline;
end;
function TWrappedDataHelper.getData: pointer;
begin
result := data;
end;
function strFromPtr(p: pointer): string;
begin
result:=IntToHex(PtrUInt(p), 2*sizeof(Pointer));
end;
procedure correct(const value: TWrappedData);
begin
writeln(strFromPtr(value.clone.getData));
end;
procedure wrong(const value: TWrappedData);
begin
with value.clone do begin
writeln(strFromPtr(getData));
end;
end;
var value: TWrappedData;
begin
value.data := pointer($1234);
wrong(value);
correct(value);
end.
What is the current bug behavior?
It prints
407FFD00
00001234
What is the expected (correct) behavior?
It should print
00001234
00001234