Hi!

I am writing my own string type and I want to overload standard string
functions.
I don't want to hide them, just overload.

Consider the following example (I use 3.0.4 [2017/10/06] for i386):

=======================================
{$MODE FPC}

type
TMyString = record
end;

function Pos(const Sub, S: TMyString): LongInt;
begin
  Pos := 0;
end;

function Length(const MyString: TMyString): SizeUInt;
begin
  Length := 0;
end;

function Copy(const MyString: TMyString; A, B: LongInt): TMyString;
begin
  Copy := MyString;
end;

begin
  // Works just fine
  Writeln(Pos('a', 'abcdef'));
  // Error: Incompatible type for arg no. 1: Got "Constant String",
expected "TMyString"
  Writeln(Copy('abcdef', 1, 4));
  // Error: Incompatible type for arg no. 1: Got "Constant String",
expected "TMyString
  Writeln(Length('abcdef'));
end.
=======================================

Pos behaves differently than Length and Copy.
Seems inconsistent -- should it be considered as a bug?

-- 
Victor Matuzenko (Виктор Матузенко)
_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to