Search code examples
delphigenericsdelphi-2010

Delphi Generics TDictionary causes [DCC Fatal Error] F2084 Internal Error: L1737 message


I just discovered generics (astonishing I know!) and immediately fell in love with it...until I found out that Delphi 2010 (update 4 & 5 installed) fail with the dreaded [DCC Fatal Error] F2084 Internal Error: L1737 message if I have this code:

// Global array of list
IDsList : Array [1..5] Of TDictionary<Int64, Int64>;

function MyProc;
var
   i : Integer;
   Enum : TDictionary<Int64, Int64>.TPairEnumerator;
begin
     // ...
     Enum := IDsList[i].GetEnumerator;
     while Enum.MoveNext do
     begin
          // ...
     end;
end;

Precisely, Delphi fails to compile unless I comment this line Enum := IDsList[i].GetEnumerator;

Using an array greatly simplify my code, is there a way to avoid this L1737 error message?

PS. I'm not new to Delphi, only generics!


Solution

  • That code compiles on my Delphi 2010, once the error in the declaration of MyProc is fixed. There's probably something else in the real code that leads to the internal error.

    In any case it makes more sense to use a for/in loop here:

    var
      Pair: TPair<Int64, Int64>;
    ....
    for Pair in IDsList[i] do
      DoSomething(Pair);
    

    And perhaps if you did that you'd escape the internal error.

    If switching to for/in doesn't sidestep the internal error then you need to supply a complete program that exhibits the fault. Try and cut it down to the smallest size possible. This is always good practice when asking question, submitting bug reports etc.

    In my experience, if you want to do any serious generics programming, without drowning in a flood of internal errors, you need to move beyond Delphi 2010.