Sign in Join

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

Mailing lists / fpc-devel / 2014-02

Re: overload question (variant vs enum subrange)

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

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

Martin Frb

Just asking this again, as I did not get any answer yet?

Is that the indented behaviour, and if so what is the reasoning for it?

Earlier message 56 lines
-------- Original Message -------- Subject: overload question (variant vs enum subrange) Date: Sun, 26 Jan 2014 19:48:42 +0000 From: Martin Frb To: FPC-Pascal users discussions 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

Sergei Gorelkin
to Martin Frb

31.03.2014 17:32, Martin Frb пишет:

Show quoted text 5 lines
Just asking this again, as I did not get any answer yet? Is that the indented behaviour, and if so what is the reasoning for it?

This behavior is hardly intended.
To get clues about what's going on, you can compile the compiler with OPT=-dEXTDEBUG, then use it with -vd to compile your tests.

So, in case of subrange of integer/byte, the overloaded procedures are matched as follows:

   Bar(TFoo);
    invalid
   Bar(LongInt);
    ex: 0 eq: 1 l1: 0 l2: 0 l3: 0 l4: 0 l5: 0 l6: 0 oper: 0 ord:  4.29496729300000047684E+0009
     - LongInt : equal
   Bar(Variant);
    ex: 0 eq: 0 l1: 0 l2: 0 l3: 0 l4: 0 l5: 0 l6: 0 oper: 1 ord:  0.00000000000000000000E+0000
     - Variant : convert_operator

And in case of subrange of enum, it becomes as follows:

   Bar(TFoo);
    ex: 0 eq: 0 l1: 1 l2: 0 l3: 0 l4: 0 l5: 0 l6: 0 oper: 0 ord:  0.00000000000000000000E+0000
     - TFoo : convert_l1
   Bar(LongInt);
    invalid
   Bar(Variant);
    ex: 0 eq: 0 l1: 1 l2: 0 l3: 0 l4: 0 l5: 0 l6: 0 oper: 0 ord:  0.00000000000000000000E+0000
     - Variant : convert_l1

Here Variant gets the same degree of compatibility with TFoo1 as TFoo, that's probably a bug in compiler (Variant should probably have same compatibility as in first case, i.e. convert_operator, if not incompatible at all).
Also, the subrange may receive the same treatment as in the first case, i.e. considered equal to its base type but with some "ordinal distance".

Regards,
Sergei

Show quoted text 65 lines
-------- Original Message -------- Subject: overload question (variant vs enum subrange) Date: Sun, 26 Jan 2014 19:48:42 +0000 From: Martin Frb To: FPC-Pascal users discussions 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. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Martin Frb
to Sergei Gorelkin
Sergei Gorelkin wrote 10 lines
31.03.2014 17:32, Martin Frb пишет: > Just asking this again, as I did not get any answer yet? > > Is that the indented behaviour, and if so what is the reasoning for it? > > This behavior is hardly intended. To get clues about what's going on, you can compile the compiler with OPT=-dEXTDEBUG, then use it with -vd to compile your tests.

Thanks.

I had already reported it. http://bugs.freepascal.org/view.php?id=25697

If ok I will add your findings to the report?

Reply by email

Sergei Gorelkin
to Martin Frb

31.03.2014 23:46, Martin Frb пишет:

Show quoted text 16 lines
On 31/03/2014 20:29, Sergei Gorelkin wrote: > 31.03.2014 17:32, Martin Frb пишет: >> Just asking this again, as I did not get any answer yet? >> >> Is that the indented behaviour, and if so what is the reasoning for it? >> >> > This behavior is hardly intended. > To get clues about what's going on, you can compile the compiler with OPT=-dEXTDEBUG, > then use it with -vd to compile your tests. Thanks. I had already reported it. http://bugs.freepascal.org/view.php?id=25697 If ok I will add your findings to the report?

Feel free to do it.

Regards,
Sergei

Reply by email