Recent

Author Topic: overloaded functions as parameters  (Read 675 times)

glorfin

  • Full Member
  • ***
  • Posts: 130
  • LMath supporter
overloaded functions as parameters
« on: April 04, 2021, 12:40:17 am »
Hi!
I have in one unit declarations:
Code: Pascal  [Select][+][-]
  1.   TTestFunc       = function(X:Float):boolean;
  2.   function Any(constref Vector:array of double; Test:TTestFunc):boolean;
  3.  
And in another one pair of functions:
Code: Pascal  [Select][+][-]
  1.   function IsZero(F:double): boolean; overload; // uses default epsilon
  2.   function IsZero(F: double; Epsilon: Float): Boolean; overload;
  3.  

And if I write somewhere:
Code: Pascal  [Select][+][-]
  1.   B := Any(V,@IsZero);
  2.  
everything works fine. If, however, the places are swapped:
Code: Pascal  [Select][+][-]
  1.   function IsZero(F: double; Epsilon: Float): Boolean; overload;
  2.   function IsZero(F:double): boolean; overload; // uses default epsilon
  3.  
compiler complains that types are incompatible.

So, my question: is it possible to modify behaviour of the compilter such that it continues search for a second function, at least is "overload" attribute is present.

Thank you in advance!
« Last Edit: April 04, 2021, 12:47:40 am by glorfin »

jamie

  • Hero Member
  • *****
  • Posts: 4472
Re: overloaded functions as parameters
« Reply #1 on: April 04, 2021, 03:17:41 am »
Yup, looks broken..

Give that guy a winning lotta ticket!

I would present that as a test case ..

Have a good day.
The only true wisdom is knowing you know nothing

MarkMLl

  • Hero Member
  • *****
  • Posts: 2565
Re: overloaded functions as parameters
« Reply #2 on: April 04, 2021, 10:00:01 am »
Check with the most recent compiler version (and trunk if necessary) and if you still get it file a bug report.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

WooBean

  • Full Member
  • ***
  • Posts: 114
Re: overloaded functions as parameters
« Reply #3 on: April 04, 2021, 10:17:46 am »
Hi,
it may be too simple question but maybe helpful - where is float type defined?
As far as plain FPC documentation says there is no such real type.

WooBean 
« Last Edit: April 04, 2021, 10:24:49 am by WooBean »
Win7/64, Lazarus 2.0.8 win64-win64, FPC 3.0.4

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 9287
  • FPC developer.
Re: overloaded functions as parameters
« Reply #4 on: April 04, 2021, 11:05:41 am »
it may be too simple question but maybe helpful - where is float type defined?
As far as plain FPC documentation says there is no such real type.

Float is defined in unit Math  https://www.freepascal.org/docs-html/rtl/math/float.html

glorfin

  • Full Member
  • ***
  • Posts: 130
  • LMath supporter
Re: overloaded functions as parameters
« Reply #5 on: April 04, 2021, 03:23:45 pm »
oops, forgot to change it. Actually, in my case at the same unit as as IsZero, depending on compilation directives may be double, single or extended. For simplicity I wrote double in the examples, but forgot to change in one place.
Hi,
it may be too simple question but maybe helpful - where is float type defined?
As far as plain FPC documentation says there is no such real type.

WooBean

PascalDragon

  • Hero Member
  • *****
  • Posts: 2989
  • Compiler Developer
Re: overloaded functions as parameters
« Reply #6 on: April 04, 2021, 03:24:05 pm »
So, my question: is it possible to modify behaviour of the compilter such that it continues search for a second function, at least is "overload" attribute is present.

It's a shortcoming of the overload selection in conjunction with parameters. Please report a bug with an example. As a workaround you can do this:

Code: Pascal  [Select][+][-]
  1. var
  2.   t: TTestFunc;
  3. begin
  4.   t := @IsZero;
  5.   B := Any(V, t);
  6. end;

glorfin

  • Full Member
  • ***
  • Posts: 130
  • LMath supporter
Re: overloaded functions as parameters
« Reply #7 on: April 04, 2021, 08:24:37 pm »
Thank you for the responses!
I created the bug: 0038705

 

TinyPortal © 2005-2018