Browse Source

* ensure that nested functions that are assigned to function pointers are considered as captured as well

Sven/Sarah Barth 1 year ago
parent
commit
b00454bb0e
1 changed files with 8 additions and 0 deletions
  1. 8 0
      compiler/pexpr.pas

+ 8 - 0
compiler/pexpr.pas

@@ -1076,6 +1076,14 @@ implementation
                 assigned(getfuncrefdef) then
                 assigned(getfuncrefdef) then
                aprocdef:=Tprocsym(sym).Find_procdef_byfuncrefdef(getfuncrefdef);
                aprocdef:=Tprocsym(sym).Find_procdef_byfuncrefdef(getfuncrefdef);
 
 
+             { ensure that the correct function is considered as captured }
+             if assigned(current_procinfo) and
+                 assigned(aprocdef) and
+                 (aprocdef.parast.symtablelevel<=current_procinfo.procdef.parast.symtablelevel) and
+                 (aprocdef.parast.symtablelevel>normal_function_level) and
+                 (current_procinfo.procdef.parast.symtablelevel>normal_function_level) then
+               current_procinfo.add_captured_sym(sym,aprocdef,current_filepos);
+
              { generate a methodcallnode or proccallnode }
              { generate a methodcallnode or proccallnode }
              { we shouldn't convert things like @tcollection.load }
              { we shouldn't convert things like @tcollection.load }
              p2:=cloadnode.create_procvar(sym,aprocdef,st);
              p2:=cloadnode.create_procvar(sym,aprocdef,st);