Nested Function Capture doesn't work in Generic Function
## Summary
When trying to capture a nested function of a generic function, FPC returns an error that the symbol can not be captured
## System Information
FPC Trunk, Windows 10
## Example Project
```pascal
program Project1;
{$mode objfpc}{$H+}
{$ModeSwitch nestedprocvars}
{$ModeSwitch functionreferences}
type
TIntFunction = reference to function: Integer;
// Works
function FourtyTwo(const AParam: Integer): TIntFunction;
function Helper: Integer;
begin
Result := 42;
end;
begin
Result := @Helper
end;
// Error
generic function GenericFourtyTwo<T>: TIntFunction;
function Helper: Integer;
begin
Result := 42;
end;
begin
Result := @Helper
end;
begin
end.
```
[Project1.pas](/uploads/4ec3c603b55d1a6e9a61d82788b7a345/Project1.pas)
issue