From 3669419bb3dd35bc94f5e6aa756bc0999b21c149 Mon Sep 17 00:00:00 2001 From: Jonas Maebe <jonas@freepascal.org> Date: Fri, 26 Aug 2016 13:02:10 +0000 Subject: [PATCH] * fixed tcasenode.simplify() in case we have to pass via a "less" branch of of a tcaselabel that also has a valid "greater" branch to arrive at the correct entry (mantis #30522) git-svn-id: trunk@34379 - --- .gitattributes | 1 + compiler/nset.pas | 4 +--- tests/webtbs/tw30522.pp | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/webtbs/tw30522.pp diff --git a/.gitattributes b/.gitattributes index 889e083c3d..9e917e2303 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15207,6 +15207,7 @@ tests/webtbs/tw30431.pp svneol=native#text/plain tests/webtbs/tw30443.pp svneol=native#text/plain tests/webtbs/tw3045.pp svneol=native#text/plain tests/webtbs/tw3048.pp svneol=native#text/plain +tests/webtbs/tw30522.pp svneol=native#text/plain tests/webtbs/tw3063.pp svneol=native#text/plain tests/webtbs/tw3064.pp svneol=native#text/plain tests/webtbs/tw3073.pp svneol=native#text/plain diff --git a/compiler/nset.pas b/compiler/nset.pas index 8d0c5a5cf2..368aa7d17c 100644 --- a/compiler/nset.pas +++ b/compiler/nset.pas @@ -873,14 +873,12 @@ implementation function tcasenode.simplify(forinline:boolean):tnode; var tmp: pcaselabel; - walkup: boolean; begin result:=nil; if left.nodetype=ordconstn then begin tmp:=labels; { check all case labels until we find one that fits } - walkup:=assigned(tmp^.greater); while assigned(tmp) do begin if (tmp^._low<=tordconstnode(left).value) and @@ -895,7 +893,7 @@ implementation exit; end; - if walkup then + if tmp^._high<tordconstnode(left).value then tmp:=tmp^.greater else tmp:=tmp^.less; diff --git a/tests/webtbs/tw30522.pp b/tests/webtbs/tw30522.pp new file mode 100644 index 0000000000..827477a2b0 --- /dev/null +++ b/tests/webtbs/tw30522.pp @@ -0,0 +1,26 @@ + +type + E = ( a, b, c ); + +begin + case b of + a: begin + write( 'a' ); + halt(1); + end; + c: begin + write( 'c' ); + halt(2); + end; + b: + begin + write( 'b' ); + halt(0); + end; + else + begin + write( '?' ); + halt(3); + end + end; +end.