
{: test that assigning a record variant with an invalid tag value
   inside a with statement causes a fatal error }

{$d+,v+}
program d120( output );

var
   w0 : record
           myRec0 :  array[1..9] of record
               case boolean of
                 true  : ( i: integer);
                 false : ( x: real);
               end; {record }
        end; {record}


   w1 : record
           myRec :  array[1..9] of record
                case t  : boolean of
                  true  : ( i: integer);
                  false : ( x: real);
            end; {record }
        end; {record}


   k: integer;

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

begin { d120 }

   with w0 do begin
      { no tag in myRec0, so this is OK }
      k := 1;
      myRec0[side].x := 100.6;
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      write( 'x is ', myRec0[side].x:1:1 );
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      myRec0[side].i := -1;
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      write( ', integer is ', myRec0[side].i );
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      writeln( ', x is ', myRec0[side].x:1:1 );
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
   end; {with}

   with w1 do begin
      k := 1;
      myRec[side].t := true;  { access i varaint }
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      myRec[side].i := -1;
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      write( 'integer is ', myRec[side].i );
      if k <> 2 then
         writeln( '**** record access has side effects ****' );

      k := 1;
      myRec[side].t := false;  { access x varaint }
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      myRec[side].x := 100.6;
      if k <> 2 then
         writeln( '**** record access has side effects ****' );
      k := 1;
      writeln( ', x is ', myRec[side].x:1:1 );
      if k <> 2 then
         writeln( '**** record access has side effects ****' );

      k := 1;
      myRec[side].i := 33;   { !!! incorrect tag/variant combo }
   end; {with}

   writeln( 'use of invalid tag not detected' );
end. { d120 }

