Page 1 of 2
issue-#125 Compiler TRAP for WITH statement
Posted: Thu Aug 25, 2016 2:14 am
by Ivan Denisov
http://community.blackboxframework.org/ ... p=711#p665
X512 wrote:Following sequence causes trap in compiler code:
According language report this code seems to be valid. With without else doesn't crash.
Re: issue-#125 Compile crashes on empty with
Posted: Thu Aug 25, 2016 2:35 am
by Ivan Denisov
Re: issue-#125 Compile crashes on empty with
Posted: Thu Aug 25, 2016 5:39 am
by Josef Templ
Re: issue-#125 Compile crashes on empty with
Posted: Thu Aug 25, 2016 7:57 am
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
Re: issue-#125 Compile crashes on empty with
Posted: Thu Aug 25, 2016 8:17 am
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?
Re: issue-#125 Compile crashes on empty with
Posted: Thu Aug 25, 2016 11:33 am
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.
Re: issue-#125 Compiler TRAP for WITH statement
Posted: Thu Aug 25, 2016 11:52 am
by Ivan Denisov
Re: issue-#125 Compiler TRAP for WITH statement
Posted: Thu Aug 25, 2016 1:50 pm
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.
Re: issue-#125 Compiler TRAP for WITH statement
Posted: Fri Aug 26, 2016 6:15 am
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...
Re: issue-#125 Compiler TRAP for WITH statement
Posted: Fri Aug 26, 2016 6:18 am
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.