Jump to content
Sign in to follow this  
Eugine Savin

Is set a nullable type? (record constraint)

Recommended Posts

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

The Delphi generics lack constraints support for enumerations and sets.

 

Share this post


Link to post
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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×