Anonymous functions: Error: Overloaded identifier "__FPCINTERNAL__ANONYMOUS_2" isn't a function
## Summary When trying to set the result of an anonymous function that returns an anonymous function to an anonymous function, the compile fails with: Error: Overloaded identifier "__FPCINTERNAL__ANONYMOUS_2" isn't a function ## System Information - **Operating system:** Linux, AlmaLinux 9.1, x86_64 - **Processor architecture:** x86-64 - **Compiler version:** 3.3.1-12460-g0e05e908d5 - **Device:** Computer ## Steps to reproduce Given this program: ```pascal program something_cool; {$Mode objfpc}{$H+} {$ModeSwitch anonymousfunctions} {$ModeSwitch functionreferences} {$ModeSwitch nestedprocvars} type TVoidFunc = reference to procedure; TFuncMaker = reference to function(const thing: string): TVoidFunc; procedure main; var cool_bingo: TVoidFunc; coolifier: TFuncMaker; begin coolifier := function (const thing: string): TVoidFunc begin result := procedure begin writeln('cool ', thing) end; end; cool_bingo := coolifier('bingo'); cool_bingo(); end; begin main; end. ``` When trying to compile it, I get: ```shell $ fpc something_cool.pas Free Pascal Compiler version 3.3.1 [2023/02/09] for x86_64 Copyright (c) 1993-2023 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling something_cool.pas something_cool.pas(19,27) Error: Overloaded identifier "__FPCINTERNAL__ANONYMOUS_2" isn't a function something_cool.pas(28) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: /home/dev/fpc_usr/lib/fpc/3.3.1/ppcx64 returned an error exitcode ``` ## Example Project See Steps to Reproduce. ## What is the current bug behavior? See Steps to Reproduce. ## What is the expected (correct) behavior? That it compiles and runs, because this compiles and runs: ```pascal program something_cool2; {$Mode objfpc}{$H+} {$ModeSwitch anonymousfunctions} {$ModeSwitch functionreferences} {$ModeSwitch nestedprocvars} type TVoidFunc = reference to procedure; TFuncMaker = reference to procedure(const thing: string; var func: TVoidFunc); function main: TVoidFunc; var cool_bingo: TVoidFunc; coolifier: TFuncMaker; n: integer = 0; begin coolifier := procedure (const thing: string; var func: TVoidFunc) begin func := procedure begin inc(n); writeln(n, ' cool ', thing); end; end; coolifier('bingo', cool_bingo); cool_bingo(); result := cool_bingo; end; var func: TVoidFunc; begin func := main; func(); end. ``` ```shell $ fpc something_cool2.pas Free Pascal Compiler version 3.3.1 [2023/02/09] for x86_64 Copyright (c) 1993-2023 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling something_cool2.pas Linking something_cool2 35 lines compiled, 0.1 sec, 144624 bytes code, 58008 bytes data $ ./something_cool2 1 cool bingo 2 cool bingo ``` ## Relevant logs and/or screenshots See Steps to Reproduce. ## Possible fixes None that I know of.
issue