Recent

Author Topic: Error: Identifier not found "specialize"  (Read 483 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
Error: Identifier not found "specialize"
« on: August 14, 2024, 09:11:48 pm »
Playing a bit with generics now and having a weird issue, it seems like specialize cannot be called in except...end block? I mean, on one hand it feels like a bug, but on the other - I guess I could understand why.

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. generic function Foo<T>: String;
  4. begin
  5.   Exit('Bar');
  6. end;
  7.  
  8. begin
  9.   try
  10.     WriteLn(specialize Foo<Integer>); // this one works
  11.   except
  12.     WriteLn(specialize Foo<Integer>); // Error: Identifier not found "specialize"
  13.   end;
  14. end.

Now the fun part that if we wrap generic specialization into a regular function it works without issues:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. generic function Foo<T>: String;
  4. begin
  5.   Exit('Bar');
  6. end;
  7.  
  8. function FooBar: String; inline;
  9. begin
  10.   Exit(specialize Foo<Integer>);
  11. end;
  12.  
  13. begin
  14.   try
  15.     WriteLn(FooBar); // this works
  16.   except
  17.     WriteLn(FooBar); // this works too
  18.   end;
  19. end.

Free Pascal Compiler version 3.3.1-15296-g6a28ac53da [2024/02/27]
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Thaddy

  • Hero Member
  • *****
  • Posts: 15923
  • Censorship about opinions does not belong here.
Re: Error: Identifier not found "specialize"
« Reply #1 on: August 14, 2024, 10:37:09 pm »
Yes. It is a bug. Plz report it.
OTOH mode Delphi works:
Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. function Foo<T>: String;
  3. begin
  4.   Exit('Bar');
  5. end;
  6.  
  7. begin
  8.   try
  9.     WriteLn(Foo<Integer>); // this one works
  10.   except
  11.     WriteLn(Foo<Integer>); // prints bar, works too.
  12.   end;
  13. end.
« Last Edit: August 14, 2024, 10:39:03 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Eugene Loza

  • Hero Member
  • *****
  • Posts: 729
    • My games in Pascal
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

 

TinyPortal © 2005-2018