Przeglądaj źródła

Merge pull request #11423 from richardkchapman/hpcc-20084

HPCC-20084 Compiler needs to check for three periods used in string slicing

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 6 lat temu
rodzic
commit
ec703eb8ea
2 zmienionych plików z 28 dodań i 1 usunięć
  1. 7 1
      ecl/hql/hqlgram.y
  2. 21 0
      ecl/regress/err1052.ecl

+ 7 - 1
ecl/hql/hqlgram.y

@@ -5814,7 +5814,7 @@ rangeOrIndices
 rangeExpr
     : expression        {
                             IHqlExpression * expr = $1.queryExpr();
-                            if (expr->isConstant() && !expr->queryType()->isInteger())
+                            if (expr->isConstant() && expr->queryValue() && !expr->queryType()->isInteger())
                                 parser->reportWarning(CategoryMistake, WRN_INT_OR_RANGE_EXPECTED, $1.pos, "Floating point index used. Was an index range intended instead?");
                             parser->normalizeExpression($1, type_int, false);
                             parser->checkPositive($1);
@@ -5822,6 +5822,9 @@ rangeExpr
                         }
     | expression DOTDOT expression
                         {
+                            IHqlExpression * expr = $3.queryExpr();
+                            if (expr->isConstant() && expr->queryValue() && !expr->queryType()->isInteger())
+                                parser->reportWarning(CategoryMistake, WRN_INT_OR_RANGE_EXPECTED, $3.pos, "Floating point index used. Was an extra . added?");
                             parser->normalizeExpression($1, type_int, false);
                             parser->normalizeExpression($3, type_int, false);
                             parser->checkPositive($1);
@@ -5829,6 +5832,9 @@ rangeExpr
                             $$.setExpr(createValue(no_range, makeNullType(), $1.getExpr(), $3.getExpr()));
                         }
     | DOTDOT expression {
+                            IHqlExpression * expr = $2.queryExpr();
+                            if (expr->isConstant() && expr->queryValue() && !expr->queryType()->isInteger())
+                                parser->reportWarning(CategoryMistake, WRN_INT_OR_RANGE_EXPECTED, $2.pos, "Floating point index used. Was an extra . added?");
                             parser->normalizeExpression($2, type_int, false);
                             parser->checkPositive($2);
                             $$.setExpr(createValue(no_rangeto, makeNullType(), $2.getExpr()));

+ 21 - 0
ecl/regress/err1052.ecl

@@ -0,0 +1,21 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+'abcde'[4/2];    // Not an error
+'abcde'[1.2];    // Error
+'abcde'[1..2];   // Not an error
+'abcde'[1...2];  // Error