More wtf compiler - I hope Allen Bauer can explain why that happens:

More wtf compiler - I hope Allen Bauer can explain why that happens:

Edit: if the static is removed it properly inlines. Originally found that issue on a record type where class functions must me marked static. Sounds like a compiler bug to me.

Edit2: It gets even crazier. Now that I know the static was responsible for not properly inlining I returned to my original type where this failed, changed it from record to class but it still failed! After going back and forth commenting out code and in the end having the excact same code as in the sample below it still failed! Move Run2 below Run in the implementation and inline fails. WTF?!

Edit3: Ok, I guess this part from the doc is telling that:
"Within a unit, the body for an inline function should be defined before calls to the function are made. Otherwise, the body of the function, which is not known to the compiler when it reaches the call site, cannot be expanded inline." So the question about static preventing the inlining stands.


program Project1;

{$APPTYPE CONSOLE}

type
  Test = class
    class var x: Integer;
    class procedure Run2; static; inline;
    class procedure Run; static; inline;
  end;

class procedure Test.Run2;
begin
  Inc(x); // <- not inlined when called from Run ?!
end;

class procedure Test.Run;
begin
  Run2; // <- inlined
end;

begin
  test.Run; // call Test.Run2
  test.Run2; // inc dword ptr [...]
  Readln;
end.

Comments