Compiler fails on operator result type overloads
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
Compiler fails to pick up the correct overload (based on result type) for non-assignment operators.
Steps to reproduce:
Compile the following program.
program project1;
{$mode objfpc}{$H+}
{$modeswitch advancedrecords}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils
{ you can add units after this };
type
TMyRec = record
public
class operator = (a: TMyRec; b: TMyRec): Integer;
class operator = (a: TMyRec; b: TMyRec): string;
end;
{ TMyRec }
class operator TMyRec. = (a: TMyRec; b: TMyRec): Integer;
begin
Result := 0;
end;
class operator TMyRec. = (a: TMyRec; b: TMyRec): string;
begin
Result := '11';
end;
var
a, b: TMyRec;
begin
if 0 = (a = b) then
if '11' = (a = b) then // << Error: Operator is not overloaded: "Constant String" = "LongInt"
writeln('ok');
readln;
end.
Additional information:
What is intended?
1.) Not to support function result overloads for operators different from assignment.
2.) Fix Error: Operator is not overloaded: "Constant String" = "LongInt".
(2) Could be dangerous. What should be used if there is the comparison operator "String = "LongInt" defined?
Mantis conversion info:
- Mantis ID: 29459
- Version: 3.1.1