Inconsistency in determining the correct overload
Original Reporter info from Mantis: Martin @martin_frb
-
Reporter name: Martin Friebe
Original Reporter info from Mantis: Martin @martin_frb
- Reporter name: Martin Friebe
Description:
The below example gives
project1.lpr(24,3) Error: Can't determine which overloaded function to call
However with
Bar(f4); // TFoo3 = byte(1)..(3);
It does compile.
This is not consistent, and I was unable to find any documentation for this difference in behaviour.
As far as I can see the following applies:
TFoo = (a1,a2,a3,a4,a5);
Byte;
are both ordinal types http://www.freepascal.org/docs-html/ref/refsu5.html#x27-260003.1.1
TFoo1 = a2..a4;
TFoo3 = byte(1)..(3);
are both are subrange of an ordinal type (and an ordinal type of their own)
Both TFoo1 and TFoo3 can be specified as param for
procedure Bar(a: Variant); overload;
if the other overloaded "Bar" are commented out.
Also both can be used as param to the Bar of the "full range"
procedure Bar(a: Integer); overload; // accepts TFoo3
procedure Bar(a: TFoo); overload; // accepts TFoo1
There seems to be no (documented) difference, why in the example one works, and the other does not.
Additional information:
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); // TFoo1 = a2..a4;
end.
Mantis conversion info:
- Mantis ID: 25697
- OS: win
- OS Build: vista
- Platform: w32
- Version: 2.7.1
- Monitored by: » Hixie (Ian Hickson)