Anonymous functions: Fatal: Internal error 200109092 issued by compiler when setting result of an anonymous function to the default for the function reference type.
Summary
When using an anonymous function that returns a function reference, the compile fails with Fatal: Internal error 200109092
when the result variable is set to the default for the function reference type.
System Information
- Operating system: Linux, AlmaLinux 9.1, x86_64
- Processor architecture: x86-64
- Compiler version: 3.3.1-12460-g0e05e908
- Device: Computer
Steps to reproduce
When trying to compile the following program:
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
cool_bingo := default(TVoidFunc);
coolifier := default(TFuncMaker);
coolifier := function (const thing: string): TVoidFunc
var
func: TVoidFunc;
begin
result := default(TVoidFunc); // <-- This is line 23
func := procedure begin writeln('cool ', thing) end;
result := func;
end;
cool_bingo := coolifier('bingo');
cool_bingo();
end;
begin
main;
end.
The compile fails as follows:
$ fpc something_cool4.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_cool4.pas
something_cool4.pas(23,14) Fatal: Internal error 200109092
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:
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.
$ 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.
Related bugs
This is related to #40142 (closed), but with a different compiler error message. This is related to #40143 (closed)
#20251 has the same internal error, but does not appear to be related.