Sign in Join

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

Mailing lists / fpc-pascal / 2014-01

overload question (variant vs enum subrange)

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

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

Martin Frb

TFoo1 is a sub range of FFoo

And it seems to match both TFoo and variant.

project1.lpr(24,3) Error: Can't determine which overloaded function to call project1.lpr(15,11) Hint: Found declaration: Bar(TFoo); project1.lpr(11,11) Hint: Found declaration: Bar(Variant);

No other type seems to be bothered by variant.
Also variant is the only type, that I found that conflicts with TFoo1

Why?

I know I can declare

   procedure Bar(a: TFoo1); overload;

and it will solve it (even if I leave all the others, because it is an exact match).

But why does a subrange of integer/byte work? Subrange of integer does not give the error, even so it could match both.

program Project1;
{$mode objfpc}
{// $mode delpti}
type
   TFoo = (a1,a2,a3,a4,a5);
   TFoo1 = a2..a4;
   TFoo2 = 1..3;
   TFoo3 = byte(1)..(3);
procedure Bar(a: Variant); overload;
begin   end;
procedure Bar(a: Integer); overload;
begin   end;
procedure Bar(a: TFoo); overload;
begin   end;
var
   f1: TFoo;
   f2: TFoo1;
   f3: TFoo2;
   f4: TFoo3;
begin
   Bar(f2);
end.

Reply by email

Martin Frb
to Martin Frb

Anybody?

Is this designed? Or is this a bug? Shall I put it on Mantis?

Martin Frb wrote 49 lines
TFoo1 is a sub range of FFoo And it seems to match both TFoo and variant. > project1.lpr(24,3) Error: Can't determine which overloaded function > to call > project1.lpr(15,11) Hint: Found declaration: Bar(TFoo); > project1.lpr(11,11) Hint: Found declaration: Bar(Variant); No other type seems to be bothered by variant. Also variant is the only type, that I found that conflicts with TFoo1 Why? I know I can declare procedure Bar(a: TFoo1); overload; and it will solve it (even if I leave all the others, because it is an exact match). But why does a subrange of integer/byte work? Subrange of integer does not give the error, even so it could match both. program Project1; {$mode objfpc} {// $mode delpti} type TFoo = (a1,a2,a3,a4,a5); TFoo1 = a2..a4; TFoo2 = 1..3; TFoo3 = byte(1)..(3); procedure Bar(a: Variant); overload; begin end; procedure Bar(a: Integer); overload; begin end; procedure Bar(a: TFoo); overload; begin end; var f1: TFoo; f2: TFoo1; f3: TFoo2; f4: TFoo3; begin Bar(f2); end.

Reply by email