Recent

Author Topic: Not used enum  (Read 4160 times)

Okoba

  • Hero Member
  • *****
  • Posts: 509
Not used enum
« on: October 08, 2023, 12:31:38 pm »
Hello,

There is a very good feature in FPC and Lazarus that shows hints for many unused things.
But I can not find such feature for Enum types, so if one of them is not used, there will be a hint that it is unused so I can take care of that. For example eB is not used in this sample and I like a hint for it.
Is there any option I can turn on, or should I request it as a feature request, to FPC team I guess? 
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   not_used_unit;  //Unit1.pas(8,3) Hint: Unit "not_used_unit" not used in Unit1
  7.  
  8. type
  9.   TEnum = (eA, eB); //Prefer a message here saying "eB" is not used
  10.  
  11. procedure Test;
  12. function Test2: TEnum;
  13.  
  14. implementation
  15.  
  16. procedure Test;
  17. var
  18.   V: TEnum; //Unit1.pas(19,3) Note: Local variable "V" not used
  19. begin
  20.  
  21. end;
  22.  
  23. function Test2: TEnum;
  24. begin
  25.   Result := eA;
  26. end;
  27.  
  28. end.

Red_prig

  • Full Member
  • ***
  • Posts: 140
Re: Not used enum
« Reply #1 on: October 08, 2023, 12:44:48 pm »
If I'm not mistaken, there is no such hint for data types.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5407
  • Compiler Developer
Re: Not used enum
« Reply #2 on: October 08, 2023, 01:00:23 pm »
Is there any option I can turn on, or should I request it as a feature request, to FPC team I guess?

First of, in your specific example TEnum is located in the interface-section of the unit, so the compiler can't warn about the enum value eB not being used unside the unit Unit1, because it might be used from another unit.

And secondly enum values can also be accessed through Str, Val, Read(Str/Ln) and Write(Str/Ln), which complicates things as variables might be used to carry the enum value, thus it's easier and less error prone to simply say nothing for enum values that are not used.

 

TinyPortal © 2005-2018