Recent

Author Topic: [SOLVED] Strange error on interface in FPC 3.3.1  (Read 850 times)

gidesa

  • Full Member
  • ***
  • Posts: 145
[SOLVED] Strange error on interface in FPC 3.3.1
« on: November 09, 2024, 02:52:55 pm »
Hello,
I have code as this:

Code: Pascal  [Select][+][-]
  1. program test;
  2. {$mode Delphi}
  3. uses
  4.     SysUtils;
  5. type
  6.   IMyInterface = interface
  7.     function    train(const samples: tobject; const labels: TArray<Integer>): Boolean;
  8.     procedure   predict(const samples: tobject; var predictions: tobject);
  9.   end;
  10.  
  11.   TMyClass = class(TInterfacedObject, IMyInterface)
  12.   private
  13.     k_nearest:      TObject;
  14.   public
  15.     constructor Create;
  16.     destructor  Destroy; override;
  17.     function    train(const samples: tobject; const labels: TArray<Integer>): Boolean;
  18.     procedure   predict(const samples: tobject; var predictions: tobject);
  19.   end;
  20.  
  21.  
  22.  
  23.  
  24.  
  25. constructor TMyClass.Create;
  26. begin
  27.   inherited Create;
  28. end;
  29.  
  30. destructor TMyClass.Destroy;
  31. begin
  32.   inherited Destroy;
  33. end;
  34.  
  35. function TMyClass.train(const samples: tobject;
  36.                           const labels: TArray<System.Integer>): Boolean;
  37. begin
  38. end;
  39.  
  40. procedure TMyClass.predict(const samples: tobject;
  41.                           var predictions: tobject);
  42. begin
  43. end;
  44.  
  45. //----------------------------------------------
  46. begin
  47. end.
  48.  

Compiling with FPC 3.3.1, Laz 3.2, Windows 11, there is a strange error.
Could be a bug?

Code: [Select]
Compile Project, Target: D:\GDS\pascal\ocvWrapper46\examples-Freepascal\DigitsRecognition\test.exe: Exit code 1, Errors: 2, Hints: 2
Hint: (11030) Start of reading config file D:\programmi\FPC3.3.1\fpc\bin\x86_64-win64\fpc.cfg
Hint: (11031) End of reading config file D:\programmi\FPC3.3.1\fpc\bin\x86_64-win64\fpc.cfg
Verbose: (11023) Free Pascal Compiler version 3.3.1-15402-ge67cccee37-dirty [2024/03/11] for x86_64
Verbose: (11023) Copyright (c) 1993-2024 by Florian Klaempfl and others
Verbose: (1002) Target OS: Win64 for x64
Verbose: (3104) Compiling test.lpr
test.lpr(35,19) Error: (3048) Function header doesn't match any method of this class "train(const TObject;const TArray$1$crcB6E8EE8F_crc39B5D60D):System.Boolean;"
test.lpr(17,17) Error: (5088) Found declaration: train(const TObject;const TArray$1$crc713F463B_crc39B5D60D):System.Boolean;
test.lpr(49,0) Verbose: (10026) There were 2 errors compiling module, stopping
Verbose: (1018) Compilation aborted
Verbose: (1018) D:\programmi\FPC3.3.1\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode
« Last Edit: November 09, 2024, 03:09:59 pm by gidesa »

Fibonacci

  • Hero Member
  • *****
  • Posts: 613
  • Internal Error Hunter
Re: Strange error on interface in FPC 3.3.1
« Reply #1 on: November 09, 2024, 02:57:35 pm »
System.Integer = SmallInt

hmmm



objpas.pp is loaded later and overrides the "Integer"
« Last Edit: November 09, 2024, 03:00:26 pm by Fibonacci »

gidesa

  • Full Member
  • ***
  • Posts: 145
Re: Strange error on interface in FPC 3.3.1
« Reply #2 on: November 09, 2024, 03:09:39 pm »
Thank you, Fibonacci! That was the cause of error.
There is System.Integer = smallint, and a different Integer = longint.
This is originally Delphi 32bit code, where there is no distinction.

cdbc

  • Hero Member
  • *****
  • Posts: 1673
    • http://www.cdbc.dk
Re: [SOLVED] Strange error on interface in FPC 3.3.1
« Reply #3 on: November 09, 2024, 03:43:30 pm »
Hi
Yup, I can confirm, that's the error.
Putting the cursor in the 'train' declaration in interface of class and do [Ctrl+Shift+C]
corrects it to compilation... even in 3.2.2
Regards Benny
« Last Edit: November 09, 2024, 03:45:10 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Fibonacci

  • Hero Member
  • *****
  • Posts: 613
  • Internal Error Hunter
Re: [SOLVED] Strange error on interface in FPC 3.3.1
« Reply #4 on: November 09, 2024, 06:01:51 pm »

gidesa

  • Full Member
  • ***
  • Posts: 145
Re: [SOLVED] Strange error on interface in FPC 3.3.1
« Reply #5 on: November 09, 2024, 06:08:36 pm »
The program was compiled in FPC for Win32 bit, and has {$Mode Delphi}.
But Delphi 32 bit has System.Integer = Integer = longint.
So also in Fpc, for mode Delphi, should be System.Integer = longint. It's not correct that it is smallint.

Thaddy

  • Hero Member
  • *****
  • Posts: 16198
  • Censorship about opinions does not belong here.
Re: [SOLVED] Strange error on interface in FPC 3.3.1
« Reply #6 on: November 09, 2024, 07:48:53 pm »
[/b] accurate statement about FPC copying Delphi.
We don't ; and that will stay that way.
If I smell bad code it usually is bad code and that includes my own code.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5759
  • Compiler Developer
Re: [SOLVED] Strange error on interface in FPC 3.3.1
« Reply #7 on: November 11, 2024, 07:50:46 pm »
So also in Fpc, for mode Delphi, should be System.Integer = longint. It's not correct that it is smallint.

That simply is not possible (or at least a solution for this is not feasible). That is one of the things that are known incompatibilties between FPC and Delphi.

jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: [SOLVED] Strange error on interface in FPC 3.3.1
« Reply #8 on: November 11, 2024, 11:58:51 pm »
So using a System.Integer gives you a 16 bit size. ?

I know that it does because I've already have tested it, it's two bytes wide.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018