Skip to content
GitLab
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    Projects Groups Topics Snippets
  • Register
  • Sign in
  • FPC Source FPC Source
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 1,394
    • Issues 1,394
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 66
    • Merge requests 66
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • FPCFPC
  • FPC SourceFPC Source
  • Issues
  • #39742
Closed
Open
Issue created May 28, 2022 by Frederic Kehrein@Warfley

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

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

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking