issue-#125 Compiler TRAP for WITH statement

Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

issue-#125 Compiler TRAP for WITH statement

Post by Ivan Denisov »

http://community.blackboxframework.org/ ... p=711#p665
X512 wrote:Following sequence causes trap in compiler code:

Code: Select all

WITH
ELSE
END;
According language report this code seems to be valid. With without else doesn't crash.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#125 Compile crashes on empty with

Post by Ivan Denisov »

User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#125 Compile crashes on empty with

Post by Josef Templ »

This is not ready for voting.
See http://community.blackboxframework.org/ ... p=711#p667.

- Josef
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#125 Compile crashes on empty with

Post by Josef Templ »

The (hopefully) correct place and change for fixing this is in DevCPV486.stat.

Code: Select all

			| Nwith:
					IF (n.left # NIL) OR (n.right # NIL) OR (n.subcl = 0) THEN IfStat(n, n.subcl = 0, next) END
instead of
					IfStat(n, n.subcl = 0, next)
Also the changes fold should be updated.

Please recreate the topic branch. The previous fixes are wrong because they change the language definition.
Such completely wrong attempts should not be in the repository because they make it hard to
see the important changes.

In the future please be more careful when proposing compiler changes.
It is very easy to mess things up in the compiler or language definition.
This is not something for a try-and-error approach.


Also the wording of the Redmine issue should be cleaned up.

Title: Compiler TRAP for WITH statement
Description: Compiling a statement of the form "WITH ELSE END" leads to a compiler TRAP.

- Josef
Last edited by Josef Templ on Thu Aug 25, 2016 8:54 am, edited 2 times in total.
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#125 Compile crashes on empty with

Post by Robert »

it still astonishes me that bugs like this keep appearing in code that could have been stable, and has been in constant use for 20+ years.

Will it ever end?
cfbsoftware
Posts: 204
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: issue-#125 Compile crashes on empty with

Post by cfbsoftware »

Robert wrote:it still astonishes me that bugs like this keep appearing in code that could have been stable, and has been in constant use for 20+ years.
I wouldn't be too concerned if I were you. I would be more astonished to find an example of this particular use of WITH in a real world application.

Unless exceptional time and effort is invested in the development of an exhaustive compiler test suite many of these obscure edge cases might never be encountered.
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: issue-#125 Compiler TRAP for WITH statement

Post by luowy »

cfbsoftware wrote:I would be more astonished to find an example of this particular use of WITH in a real world application.
me too, treat it as a bug as first glance,it is ridiculous accepting such code by the compiler.
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#125 Compiler TRAP for WITH statement

Post by Ivan Denisov »

luowy wrote:
cfbsoftware wrote:I would be more astonished to find an example of this particular use of WITH in a real world application.
me too, treat it as a bug as first glance,it is ridiculous accepting such code by the compiler.
It seems that Josef is right for this case.
9.11 With Statements

With statements execute a statement sequence depending on the result of a type test and apply a type guard to every occurrence of the tested variable within this statement sequence.

WithStatement = WITH [ Guard DO StatementSequence ]
{"|" [ Guard DO StatementSequence ] }
[ELSE StatementSequence] END.
Guard = Qualident ":" Qualident.

If v is a variable parameter of record type or a pointer variable, and if it is of a static type T0, the statement

WITH v: T1 DO S1 | v: T2 DO S2 ELSE S3 END

has the following meaning: if the dynamic type of v is T1, then the statement sequence S1 is executed where v is regarded as if it had the static type T1; else if the dynamic type of v is T2, then S2 is executed where v is regarded as if it had the static type T2; else S3 is executed. T1 and T2 must be extensions of T0. If no type test is satisfied and if an else clause is missing the program is aborted.

Example:
WITH t: CenterTree DO i := t.width; c := t.subnode END
So WITH ELSE END is correct meaningless construction...
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#125 Compiler TRAP for WITH statement

Post by Ivan Denisov »

I have tested the version 1.7-rc1.642
http://blackboxframework.org/unstable/i ... c1.642.zip

Not trap. And all is working.
Post Reply