Eugine Savin 4 Posted May 5, 2021 if I pass set type into MyGenericMethod<T: record> - I get compile type error [dcc32 Error] Project2.dpr(28): E2512 Type parameter 'T' must be a non-nullable value type Is it OK or compiler bug ?? program Project2; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils; type TMyEnum = (en1); TMySet = set of TMyEnum; type TTestClass = class class procedure MyGenericMethod<T: record>; end; class procedure TTestClass.MyGenericMethod<T>; begin // end; begin try { TODO -oUser -cConsole Main : Insert code here } TTestClass.MyGenericMethod<TMySet>(); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. Share this post Link to post
Lars Fosdal 1792 Posted May 5, 2021 The Delphi generics lack constraints support for enumerations and sets. Share this post Link to post
Eugine Savin 4 Posted May 5, 2021 As least Delphi Tokio compiles this code successfully Share this post Link to post
Dalija Prasnikar 1396 Posted May 5, 2021 1 hour ago, Eugine Savin said: As least Delphi Tokio compiles this code successfully If it works in Tokyo you should report compiler regression to Quality Portal https://quality.embarcadero.com/ This is probably due to introduction of custom managed records that need additional handling and they broke record constraint that is basically constraint for value types. I had similar issue with variant records https://quality.embarcadero.com/browse/RSP-28761 Share this post Link to post
David Heffernan 2345 Posted May 5, 2021 The code fails to compile in XE7 with the same E2512 error. I consider a set type to be a non-nullable value type so this must be a defect. Share this post Link to post
Stefan Glienke 2002 Posted May 5, 2021 No version ever compiled this code - I just checked with XE8 to 10.4 (all the latest update/hotfixes) Reported since 10.0.1 - see https://quality.embarcadero.com/browse/RSP-13198 Share this post Link to post
Eugine Savin 4 Posted May 5, 2021 Oh, sorry, my fault, I believe that I have similar code but it does not have generic constraints. Perhaps I ran into this issue earlier, but forgot about it Share this post Link to post