Sign in Join

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

Mailing lists / fpc-devel / 2021-01

Generics-related compilation issue

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Werner Pamler

A happy, successful and healthy New Year to everybody!

I have a generics related compilation issue in my package ExCtrls package
(https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/exctrls/). This package contains a TCurrencySpinEditEx component which inherits from the TSpinEditExBase component of the LazControls package coming with Lazarus. TSpinEditExBase introduces generic fields FValue, FIncrement, FMaxValue etc, and each decendent of it specializes these types, i.e. in TCustomFloatSpinEditEx FValue, FIncrement, FMaxValue are double, and in the CurrencySpinEdit for the ExCtrls package they are currency values.

The compilation of the ExCtrls package fails for example in the IncrementStored method of TSpinEditExBase

     function TSpinEditExBase.IncrementStored: Boolean;
     begin
       Result := not SameValue(FIncrement, DefIncrement);   // <---
error here; SameValue is from unit Math
     end;

the error message says: "Can't determine which overloaded function to call". FIncrement and DefIncrement are generic types here.

What is strange to me is that the compilation issue does not happen with the LazControls package alone, but only when ExCtrls package is added.  Moreover, the problem occurs only on 64bit, not on 32 bit. (I am on Windows)

I can solve the compilation issue by moving the IncrementStored method into the derived classes. But this kind of contradicts the idea with using generic types in the first place.

Is there another way to solve this issue?

Werner

Reply by email

Bart
to Werner Pamler
PM Werner Pamler wrote
What is strange to me is that the compilation issue does not happen with the LazControls package alone, but only when ExCtrls package is added. Moreover, the problem occurs only on 64bit, not on 32 bit. (I am on Windows)

Currency on 64-bit might be the culprit. IIRC it had another datatype then on other platforms.

Bart

Reply by email

Bart
to Bart
PM Bart wrote
> What is strange to me is that the compilation issue does not happen with > the LazControls package alone, but only when ExCtrls package is added. > Moreover, the problem occurs only on 64bit, not on 32 bit. (I am on Windows)

64-bit Windows:
CompareValue(constant, currencyvariable):
3.2.0: OK.
Trunk: Error: Can't determine which overloaded function to call

CompareValue(currencyvariable, currencyvariable):
3.2.0: Error: Can't determine which overloaded function to call. Trunk: OK

CompareValue(currencyvariable, constant):
3.2.0: OK
Trunk: Error: Can't determine which overloaded function to call

32-bit fpc 3.2.0/trunk: no problem.

So, most likely this has nothing to do with generics? I'm using r47193 of fpc trunk

@wp: a temporary fix for compiling ExCtrls with fpc trunk would be to assign the constant to a temp variable (in TSpinEditExBase)?

Bart

Reply by email

Bart
to Bart
PM Bart wrote
So, most likely this has nothing to do with generics? I'm using r47193 of fpc trunk

Try to compile attached program for Win64-bit with either 3.2.0 or trunk:

Free Pascal Compiler version 3.2.0 [2020/06/04] for x86_64 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win64 for x64
Compiling c.lpr
c.lpr(17,3) Error: Can't determine which overloaded function to call c.lpr(22) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted

Free Pascal Compiler version 3.3.1 [2021/01/04] for x86_64 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win64 for x64
Compiling c.lpr
c.lpr(15,3) Error: Can't determine which overloaded function to call c.lpr(19,3) Error: Can't determine which overloaded function to call c.lpr(22) Fatal: There were 2 errors compiling module, stopping Fatal: Compilation aborted

Casting the constant to currency allows compiling in trunk (but then fails in 3.2.0)

Bart

Reply by email