Compiling code using TDictionary from Generics.Collections results in a number of warnings and notes that developer cannot do anything about
Compiling the testcase https://github.com/michaliskambi/modern-pascal-introduction/blob/master/code-samples/generics_dictionary.lpr with latest FPC from main branch results in 8 warnings and 6 notes:
$ fpc generics_dictionary.lpr
Free Pascal Compiler version 3.3.1-12591-gdb66d8f057 [2023/03/28] for x86_64
Copyright (c) 1993-2023 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling generics_dictionary.lpr
generics.collections.pas(1279,20) Note: Call to subroutine "function TEnumerable<System.AnsiString>.GetEnumerator:TEnumerator$1$crc8D68C026_crc1CEAE787;" marked as inline is not inlined
generics.collections.pas(1279,20) Note: Call to subroutine "function TEnumerable<Program.TApple>.GetEnumerator:TEnumerator$1$crc0EBA89EB_crc1CEAE787;" marked as inline is not inlined
generics.collections.pas(1279,20) Note: Call to subroutine "function TEnumerable<Program.TPair<System.AnsiString,Program.TApple>>.GetEnumerator:TEnumerator$1$crc7ED07D64_crc1CEAE787;" marked as inline is not inlined
generics.defaults.pas(874,14) Warning: An inherited method is hidden by "Equals(const AnsiString;const AnsiString):System.Boolean;"
generics.defaults.pas(875,14) Warning: An inherited method is hidden by "GetHashCode(const AnsiString):System.LongWord;"
generics.dictionaries.inc(191,92) Warning: Constructing a class "TCustomDictionaryEnumerator$4$crcC194F725_crc1CEAE787" with abstract method "DoMoveNext"
generics.dictionaries.inc(191,92) Warning: Constructing a class "TCustomDictionaryEnumerator$4$crcC194F725_crc1CEAE787" with abstract method "GetCurrent"
generics.dictionaries.inc(191,92) Warning: Constructing a class "TCustomDictionaryEnumerator$4$crcFD6290EE_crc1CEAE787" with abstract method "DoMoveNext"
generics.dictionaries.inc(191,92) Warning: Constructing a class "TCustomDictionaryEnumerator$4$crcFD6290EE_crc1CEAE787" with abstract method "GetCurrent"
generics.defaults.pas(874,14) Warning: An inherited method is hidden by "Equals(const TApple;const TApple):System.Boolean;"
generics.defaults.pas(875,14) Warning: An inherited method is hidden by "GetHashCode(const TApple):System.LongWord;"
generics.collections.pas(150,52) Note: Private type "TCustomPointersEnumerator$2<SYSTEM.AnsiString,PROGRAM.TCustomList$1$crc8D68C026_crc1CEAE787.PT>.T" never used
generics.collections.pas(150,52) Note: Private type "TCustomPointersEnumerator$2<PROGRAM.TApple,PROGRAM.TCustomList$1$crc0EBA89EB_crc1CEAE787.PT>.T" never used
generics.collections.pas(150,52) Note: Private type "TCustomPointersEnumerator$2<PROGRAM.TPair$2<SYSTEM.AnsiString,PROGRAM.TApple>,PROGRAM.TCustomList$1$crc7ED07D64_crc1CEAE787.PT>.T" never used
Linking generics_dictionary
49 lines compiled, 0.7 sec, 824144 bytes code, 478336 bytes data
8 warning(s) issued
6 note(s) issued
There are really 3 or 4 of them (depending on how you count):
- Note: Private type xxx never used
- Note: Call to subroutine xxx marked as inline is not inlined
- Warning: An inherited method is hidden by "Equals(const xxx;const xxx):System.Boolean;"
- Warning: An inherited method is hidden by "GetHashCode(const xxx):System.LongWord;"
From the point of view of developer just using Generics.Collections
unit, it seems I cannot really do anything about these warnings and notes. And I guess they are actually harmless, since at least the 2 notes are emitted since a long time by FPC, and I didn't observe any adverse effects.
My suggestion is to somehow avoid their generation for instances of generics from Generics.Collection
. I haven't tested whether actually enclosing the generics implementation in Generics.Collection
in {$push} {$warnings off} {$notes off} ... {$pop}
makes any effect on the code using these generics, maybe this is an easy way.
Note:
-
I know I can hide these notes and warnings using proper FPC options
-vmXXXX
, but that's a pity. I generally want to see warnings and notes, I'm generally interested in notes about unused private types, I'm definitely interested in warnings about hidden inherited methods. So I don't want to just universally hide this type of warnings/notes from my output. CGE build tool already has to hide some FPC warnings/notes that are not useful. -
I could also hide them selectively in my code using
{$push} {$warnings off} {$notes off} ... {$pop}
around their usage. But this is impractical for a real code using these generics intensively -- I would need to surround a lot of code in it. -
It's not a good default anyway, if by default we generate 14 warnings/notes for a simple testcase, where developer is doing everything correct (according to my knowledge, testcase https://github.com/michaliskambi/modern-pascal-introduction/blob/master/code-samples/generics_dictionary.lpr presents a valid way of using
TDictionary
).