Sorry no Lazarus project, I am still used to work with the Textmode IDE. And I know the generator is crap, this is just for testing.Bug reproduced. А simplified version that is also suitable for Delphi:
FPC3.2.2, win32, mode objfpc
Create instance of TSys...In Delphi:
TSys now being created
State=0
Create instance of TSys...
TState now being initialised
TSys now being created
State=1
Maybe the fix already solved that - sorry I cannot test because I don't understand gitlab.
Fixed in 27c1bb3b (https://gitlab.com/freepascal.org/fpc/source/-/commit/27c1bb3beaa237e9813194205425c312b6308cbd). If no issues occur this will likely be merged to 3.2.3 as well.
The same problem occurs when using an instance of an advanced record declared globally in another unit: The initalization is not called.From point of logic I would agree that such try needs to fail. It simple would make no sense. Imagine 10 units that include your super-record-unit, each change the value, who is correct?
Fixed in 27c1bb3b (https://gitlab.com/freepascal.org/fpc/source/-/commit/27c1bb3beaa237e9813194205425c312b6308cbd). If no issues occur this will likely be merged to 3.2.3 as well.
...and you want to implement BPLs...
I reopen this thread because I stumbled across a very similar issue: The same problem occurs when using an instance of an advanced record declared globally in another unit: The initalization is not called.
Also managed records and dynamic packages are at two different places of the initialization: the issue with managed records is here that the implicit initialization function is not populated correctly, because managed records are the first types that aren't initialized to 0 / Nil, but instead need more functionality. Dynamic packages on the other hand basically need a rework of the whole unit initialization/finalization which includes the implicit initialization as a little part (though how implicit initialization itself works wouldn't be touched as part of this).
If you care i might look for my old test project on this issue, so you would have a particularly nasty BPL code-twister for tests.
Can someone please test and confirm, then I'll file a bug report.