Recent

Author Topic: Problem wih reference to procedure  (Read 641 times)

henrique

  • Newbie
  • Posts: 1
Problem wih reference to procedure
« on: March 07, 2026, 02:39:50 pm »
Hi!

I'm trying to compile this source code:
Code: Pascal  [Select][+][-]
  1. unit Error;
  2.  
  3. interface
  4.  
  5. {$mode objfpc}
  6. {$modeswitch functionreferences}
  7.  
  8. type
  9.   TProc = reference to procedure;
  10.   generic TProc<T> = reference to procedure (Arg1: T);
  11.   generic TProc<T1,T2> = reference to procedure (Arg1: T1; Arg2: T2);
  12.  
  13. implementation
  14.  
  15. end.
  16.  

The compiler give the error:
Quote
Error.pp(10,22) Error: Duplicate identifier "TProc$1"
Error.pp(11,26) Error: Duplicate identifier "TProc$2"
Error.pp(15,1) Fatal: There were 2 errors compiling module, stopping

It's a problem from compiler or I'm missing some modeswitch?

PascalDragon

  • Hero Member
  • *****
  • Posts: 6393
  • Compiler Developer
Re: Problem wih reference to procedure
« Reply #1 on: March 07, 2026, 11:16:41 pm »
Non-Delphi modes do not yet support type overloads. So if you want to use type overloads you need to use mode Delphi.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12842
  • FPC developer.
Re: Problem wih reference to procedure
« Reply #2 on: March 07, 2026, 11:28:55 pm »
If I change it to
Code: Pascal  [Select][+][-]
  1. unit Error;
  2.  
  3. interface
  4.  
  5. {$mode objfpc}
  6. {$modeswitch functionreferences}
  7.  
  8. type
  9.   TProc = reference to procedure;
  10.   generic TProc<T> = reference to procedure (Arg1: T);
  11.   generic TProcz<T1,T2> = reference to procedure (Arg1: T1; Arg2: T2);
  12.  
  13. implementation
  14.  
  15. end.

The problem is still the same with todays snapshot

Code: Pascal  [Select][+][-]
  1. <something>pp(10,22) Error: Duplicate identifier "TProc$1"

so it is not just overloading?

Thausand

  • Hero Member
  • *****
  • Posts: 532
Re: Problem wih reference to procedure
« Reply #3 on: March 07, 2026, 11:54:18 pm »
If I change it to
is may be copy-paste error ? (code is same = mode objfpc)

A docile goblin always follow HERMES.md

PascalDragon

  • Hero Member
  • *****
  • Posts: 6393
  • Compiler Developer
Re: Problem wih reference to procedure
« Reply #4 on: March 08, 2026, 12:09:44 am »
so it is not just overloading?

It is. TProc and TProc<T> are still overloaded. It's not relevant here that one is generic and the other is not, from the compiler's point of view the symbol of TProc is the one that needs to be overloaded.

If I change it to
is may be copy-paste error ? (code is same = mode objfpc)

No, it's no the same, note the TProcz<T1,T2>

 

TinyPortal © 2005-2018