Browse Source

* ensure that the nested procdef's internal fields are properly reset when its adjusted
+ added test

Sven/Sarah Barth 1 month ago
parent
commit
1ecf9a6ef9
2 changed files with 33 additions and 0 deletions
  1. 1 0
      compiler/procdefutil.pas
  2. 32 0
      tests/test/tfuncref56.pp

+ 1 - 0
compiler/procdefutil.pas

@@ -1010,6 +1010,7 @@ implementation
           { fix function return symbol }
           pd.funcretsym:=pinested.procdef.funcretsym;
           pinested.procdef.funcretsym:=nil;
+          pinested.procdef.reset_after_conv;
           insert_funcret_para(pinested.procdef);
           insert_funcret_local(pinested.procdef);
           { the nested function needs access to the parent's framepointer to

+ 32 - 0
tests/test/tfuncref56.pp

@@ -0,0 +1,32 @@
+unit tfuncref56;
+
+{$mode objfpc}{$H+}
+{$modeswitch advancedrecords}
+{$modeswitch functionreferences}
+
+interface
+
+type
+  TCallback = reference to procedure(aSelf: TObject);
+  TMethodImplementationCallback = reference to procedure(aUserData: Pointer);
+
+  TTest = class
+    function CreateImplementation(aCallback: TCallback): TMethodImplementationCallback;
+  end;
+
+
+implementation
+
+function TTest.CreateImplementation(aCallback: TCallback): TMethodImplementationCallback;
+
+  procedure SelfCallback(aUserData: Pointer);
+  begin
+    aCallback(TObject(aUserData));
+  end;
+
+begin
+  Result := @SelfCallback;
+end;
+
+end.
+