
{: test that function without a return value causes a fatal error }

{$d+}
program d015( output );

var
   k  : integer;

function side : integer;
begin
   side := k;
   k := k+1;
end; { side }

function outer(a :  integer ) : integer;

label 1;

function gtest(a :  integer ) : integer;
begin
   writeln( 'unassigned return value caused by goto' );
   goto 1;
   {it is allowed to exit via a goto before setting function result}
   gtest := 32;
end; { gtest }

{$d-} function {$d+} notest(a :  integer ) : integer;
begin
   if a < 0 then begin
      { !!! no return value }
      notest := 2*side
   end;
   writeln( 'unassigned return value not detected because debug disabled' );
end; { notest }
function test(a :  integer ) : integer;
begin
   k := a;
   if k<=23 then
      test := 2*side
   { !!! no return value if a > 23 }
end; { test }

begin {outer}
   outer := notest(a);
   if a = 23 then
      outer := gtest(a);
1:
   outer := test(a);
end; { outer }


begin {d015}
   writeln( 'outer(23) is ', outer(23):1 );
   if k <> 24 then
      writeln( 'side effect error' );
   writeln( 'outer(24) is ', outer(24):1 );
   writeln( 'unassigned function value not detected' );
end. { d015 }

