Jump to content
rgdawson

Custom Managed Record - Compiler Fail "F2084 Internal Error C25335"

Recommended Posts

FYI, I ran into this interesting case in one of my apps so I created simple example to reproduce.

 

The example uses a combination of a Custom Managed Record, a class function that returns the CMR type, and inline variables with a variable assigned to an anonymous function inline, and where the anonymous function captures the CMR variable.

 

In my simple example, compilation fails with "F2084 Internal Error C25335". 

 

It will compile fine if the function is defined as a nested function, instead of inline/anonymous.  In my application, I have also seen this case compile, however the CMR initialization/finalization  does not occur correctly.  So, here is another case where Custom Managed Records have bugs. 

 

Here is the code:

program CmrTest;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

type
  TMyRecord = record
  private
    FValue: Integer;
  public
    class operator Initialize (out Dest: TMyRecord);
    class function New(Value: integer): TMyRecord; static;
    property Value: integer read FValue write FValue;
  end;

class operator TMyRecord.Initialize(out Dest: TMyRecord);
begin
  Dest.FValue := 10;
end;

class function TMyRecord.New(Value: integer): TMyRecord;
begin
  Result.Value := Value;
end;

{$DEFINE ERRORCASE}

{$IFDEF ERRORCASE}
procedure TestCase;  {!! Compile fails with "F2084 Internal Error C25335"}
begin
  var MyRecord := TMyRecord.New(20);
  var DivBy10 := function: integer
    begin
      Result := MyRecord.Value div 10;
    end;
end;
{$ELSE}
procedure TestCase;  {Compiles OK}
var
  MyRecord: TMyRecord;

  function DivBy10: Integer;
  begin
    Result := MyRecord.Value div 10;
  end;

begin
  MyRecord := TMyRecord.New(20);
end;
{$ENDIF}

begin
  try
    TestCase;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

 

Edited by rgdawson

Share this post


Link to post

Thanks, that's interesting.  That explains why I saw different behavior in my app.  The example was 32-bit, where compile fails.  In 64-bit it does compile, but actually still does not work correctly.  Good to know Embarcadero is on 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

×