Private property of a Generic Type
Summary
I have codes like this that worked just find until recent versions, but current Trunk says "unit1.pas(22,5) Error: Identifier idents no member "A"" Why? And what can I do to fix it? I do not want to expose these fields.
System Information
Windows 10, FPC Trunk from 2024-02-24. What I know is until 2024-02-02 it is working but when I get the latest trunk I get this error.
Steps to reproduce
In current Trunk run the sample code.
Example Project
program Project1;
{$mode Delphi}
uses
unit1;
var
V: TTest<Integer>;
begin
Inc<Integer>(V);
ReadLn;
end.
unit Unit1;
{$mode Delphi}
interface
type
TTest<T> = record
private
A: T;
end;
procedure Inc<T>(var v: TTest<T>);
implementation
procedure Inc<T>(var v: TTest<T>);
begin
V.A += 1; //Error!
end;
end.
It is not about privatizing all properties, it can happen in these samples too:
type
TTest<T> = record
B: Integer;
X: String;
private
MyPrivateValueToHandle: T;
end;
procedure Inc<T>(var v: TTest<T>);
implementation
procedure Inc<T>(var v: TTest<T>);
begin
V.MyPrivateValueToHandle += 1; //Error!
end;
end.
What is the expected (correct) behavior?
There are values that you don't want outside can handle, or even IDE suggest it in code suggestion. And it is not consistent and logical that a function has no access to a property in the same unit. Even if we say the type was specialized in the program, the Add function was specialized there too, so both should see each other.
Relevant logs and/or screenshots
Forum post: https://forum.lazarus.freepascal.org/index.php/topic,66393.msg508467.html#msg508467