Parcourir la source

HPCC-14454 Fix incorrect constant folding of CHOOSE(0,...)

It would evaluate to 0, instead of the default value

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday il y a 9 ans
Parent
commit
20ffb69101
2 fichiers modifiés avec 12 ajouts et 3 suppressions
  1. 6 3
      ecl/hqlcpp/hqlttcpp.cpp
  2. 6 0
      ecl/regress/issue14454.ecl

+ 6 - 3
ecl/hqlcpp/hqlttcpp.cpp

@@ -11785,9 +11785,12 @@ IHqlExpression * HqlTreeNormalizer::createTransformed(IHqlExpression * expr)
             if (condValue)
             {
                 unsigned idx = (unsigned)condValue->getIntValue();
-                IHqlExpression * branch = queryRealChild(expr, idx);
-                if (branch)
-                    return transform(branch);
+                if (idx != 0)
+                {
+                    IHqlExpression * branch = queryRealChild(expr, idx);
+                    if (branch)
+                        return transform(branch);
+                }
                 IHqlExpression * defaultExpr = queryLastNonAttribute(expr);
                 return transform(defaultExpr);
             }

+ 6 - 0
ecl/regress/issue14454.ecl

@@ -0,0 +1,6 @@
+toText(UNSIGNED1 i) := CHOOSE(i,'one','two','elsevalue');
+OUTPUT(toText(0));
+OUTPUT(toText(1));
+OUTPUT(toText(2));
+OUTPUT(toText(3));
+OUTPUT(toText(4));