Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2016-02

ifthen bugs (maybe)

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin

just found some issues

Neither syntax works in constant evaluation.
Not sure if they should, so asking here (the 2nd syntax is operator like, so kind of expected it would)

both cause an internal error trying to take the address of the returned candidate.
Then again this might not be a valid operation, but instead of internal error it should then give a more proper error.

program Project1;
{$mode objfpc}
const a = 1 + 2;
//const a = ifthen(true, 1,2);
//const a = if true then 1 else 2;
var b: integer;
var x : pointer;
begin
   //x :=  @( if false then b else b);  // internal error
   //x :=  @( ifthen( false , b , b));  // internal error
   writeln(a);
   writeln(ptrint(x));
   readln;
end.
Another internal error when using with the in operator.
program Project1;
{$mode objfpc}
var b: integer;
begin
   b := 1;
   writeln(b in [1,2] );
   //writeln(b in ifthen( true , [1,2] , [3.4])); // internal error
   //writeln(b in if true then [1,2] else [3.4]);  // internal error
   readln;
end.

And this compiles, but nothing get incremented.
If it should not work, then should it give an error? (such as "variable identifier expected" which you get when you try to pass other not incrementable expressions )

program Project1;
{$mode objfpc}
var b: integer;
begin
   b := 0;
   writeln(b);
   inc( if true then b else b );
   writeln(b);
   inc( ifthen( true ,b ,b ));
   writeln(b);
   readln;
end.
same with readln
   readln( if true then b else b   );
   writeln(b);
   readln( ifthen( true ,b ,b ));
   writeln(b);

Reply by email

Sven Barth
to Martin
"Martin" wrote 5 lines
just found some issues Neither syntax works in constant evaluation. Not sure if they should, so asking here (the 2nd syntax is operator like,

so kind of expected it would)

both cause an internal error trying to take the address of the returned

candidate.

Then again this might not be a valid operation, but instead of internal

error it should then give a more proper error.

Show quoted text 33 lines
program Project1; {$mode objfpc} const a = 1 + 2; //const a = ifthen(true, 1,2); //const a = if true then 1 else 2; var b: integer; var x : pointer; begin //x := @( if false then b else b); // internal error //x := @( ifthen( false , b , b)); // internal error writeln(a); writeln(ptrint(x)); readln; end. Another internal error when using with the in operator. program Project1; {$mode objfpc} var b: integer; begin b := 1; writeln(b in [1,2] ); //writeln(b in ifthen( true , [1,2] , [3.4])); // internal error //writeln(b in if true then [1,2] else [3.4]); // internal error readln; end. And this compiles, but nothing get incremented. If it should not work, then should it give an error? (such as "variable identifier expected" which you get when you try to

pass other not incrementable expressions )

Show quoted text 19 lines
program Project1; {$mode objfpc} var b: integer; begin b := 0; writeln(b); inc( if true then b else b ); writeln(b); inc( ifthen( true ,b ,b )); writeln(b); readln; end. same with readln readln( if true then b else b ); writeln(b); readln( ifthen( true ,b ,b )); writeln(b);

Would you please report all three of them? I don't necessarily know the best solution for problems 1 and 3, but internal errors definitely aren't the answer...

Regards,
Sven

Reply by email