Sunday, September 23, 2012

XE3: Internal Error G9413

Today I wanted to check whether the OmniThreadLibrary plays nice with XE3 (yes, I know, I’ve should have done this weeks ago, but there was simply not enough time) and I was completely surprised when OtlSync unit couldn’t be compiled due to an internal error G9413.

One hour later I have reduced the problem to a simple test case (below) and to a simple fix. So the OmniThreadLibrary will be supported in the XE3 (as we all hoped for).

For other poor souls that may have run into this problem, here’s a small test case and a workaround.

implementation

uses
RTTI;

type
TTest<T> = class
procedure Test;
end;

var
a: IInterface;

procedure TTest<T>.Test;
var
aMethCreate: TRttiMethod;
begin
if Length(aMethCreate.GetParameters) = 0 then
;

end;

initialization
a := nil; // F2084 Internal Error: G9413
end.

The problem here is that the G9413 internal error is not reported on the line which causes the problem. The real culprit here is the ‘if Length(aMethCreate.GetParameters)’ call in the ‘TTest<T>.Test’ method.

To fix the problem it is enough to introduce a temporary variable that stores the result of the GetParameters call.

unit Unit136;

interface

implementation

uses
RTTI;

type
TTest<T> = class
procedure Test;
end;

var
a: IInterface;

procedure TTest<T>.Test;
var
aMethCreate: TRttiMethod;
params : TArray<TRttiParameter>;
begin
params := aMethCreate.GetParameters;
if Length(params) = 0 then
;
end;

initialization
a := nil;
end.

The problem is reported as QC #108942.

5 comments:

  1. Anonymous23:19

    Isn't unassigned the correct value, not nil?

    ReplyDelete
  2. Anonymous23:21

    Actually, now that I think about it, the assignment shouldn't even be required. A should default to unassigned/nil because it's a unit global variable, and reference counted.

    ReplyDelete
    Replies
    1. This is just a minimal test case. In reality, 'a' was assigned an instance of some interface.

      Delete
  3. Anonymous21:45

    What happens if you turn off compiler optimizatioins?

    ReplyDelete
    Replies
    1. Optimization was turned off during my test. Turning it on doesn't change the result.

      Delete