Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2005-01

Operator overloading broken in 1.9.6?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Vinzent Hoefler

Hi,

just installed 1.9.6 to see if any of our current code will break and unfortunately I wasn't disappointed. ;-)

stripped down code:

-- 8< -- snip --
unit

   StrTools;
interface
operator * (const C : Char; const Len : byte) s : String;
implementation
operator * (const C : Char; const Len : byte) s : string;
var
   i : byte;
begin
   s := '';
   for i := 1 to Len do
      s := s + C;
end {"*"};

end {StrTools}.
-- 8< -- snip --

This compiled fine with 1.0.10, but 1.9.6 now bails out with "Error: Impossible operator overload" as early as at the line where the operator is declared.

Is this a bug? A feature? Or just me being stupid?

Vinzent.

Peter Vreman
to Vinzent Hoefler
Show quoted text 35 lines
Hi, just installed 1.9.6 to see if any of our current code will break and unfortunately I wasn't disappointed. ;-) stripped down code: -- 8< -- snip -- unit StrTools; interface operator * (const C : Char; const Len : byte) s : String; implementation operator * (const C : Char; const Len : byte) s : string; var i : byte; begin s := ''; for i := 1 to Len do s := s + C; end {"*"}; end {StrTools}. -- 8< -- snip -- This compiled fine with 1.0.10, but 1.9.6 now bails out with "Error: Impossible operator overload" as early as at the line where the operator is declared. Is this a bug? A feature? Or just me being stupid?

There must be at least one complex type record/string/array involved. Your example is only using 2 ordinal types. At the time that the expression is parsed the result is not known so the complex string result has no influence.

Example of things that are ambigious:

procedure p1(b:byte);
procedure p1(s:string);
p1(char*byte);

This can be a missing type cast and therefor the compiler shall give an error. Also you can see here that the result of byte*char can't be known yet at the time it is parsed. Because the type of the argument needed by p1() can be either string or byte.

Vinzent Hoefler
to Peter Vreman
Peter Vreman wrote
> operator * (const C : Char; const Len : byte) s : String;

[doesn't work anymore]

Show quoted text 5 lines
There must be at least one complex type record/string/array involved. Your example is only using 2 ordinal types. At the time that the expression is parsed the result is not known so the complex string result has no influence.

Hmm, guess I just have to accept this. ;-) This routine was just for fun anyway..., nothing serious.

Ok, after trying to compile some more (hey, you guys invented a lot of new warnings, ;-) thank you), here's my next problem, I can't understand:

-- 8< -- snip --
program

   Bug;

{ use a structured type used to keep the namings clean } type
tLoopParm =
record
Min,
Max,

      Cur : word;
   end {tLoopParm};

var
One,
Two,
Three,

   Four : tLoopParm;
begin
   One.Min := 42;
   One.Max := 42;
   for One.Cur := One.Min to One.Max do
   begin
      Two.Min := 42;
      Two.Max := 42;
      for Two.Cur := Two.Min to Two.Max do // <- line 28
      begin
         Three.Min := 42;
         Three.Max := 42;
         for Three.Cur := Three.Min to Three.Max do // <- line 33
         begin
            Four.Min := 42;
            Four.Max := 42;
            for Four.Cur := Four.Min to Four.Max do // <- line 38
            begin
               // code
            end {for Four};
         end {for Three};
      end {for Two};
   end {for One};
end {Bug}.

-- -- --

Target OS: Linux for i386
Compiling bug.pas
bug.pas(28,30) Error: Illegal assignment to for-loop variable "Cur"
bug.pas(33,37) Error: Illegal assignment to for-loop variable "Cur"
bug.pas(38,38) Error: Illegal assignment to for-loop variable "Cur"
bug.pas(45,10) Fatal: There were 3 errors compiling module, stopping

-- 8< -- snip --

This doesn't make sense, does it?

As mentioned before, all this code compiled fine with fpc-1.0.10 (Linux, DOS & Windows targets).

Vinzent.