Browse Source

Merge pull request #11891 from ghalliday/functionfunction

HPCC-20862 Avoid assert defining a function that returns a function

Reviewed-By: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 6 years ago
parent
commit
1ddd49ff62
3 changed files with 25 additions and 0 deletions
  1. 2 0
      ecl/hql/hqlerrors.hpp
  2. 6 0
      ecl/hql/hqlgram2.cpp
  3. 17 0
      ecl/regress/dlingle1.ecl

+ 2 - 0
ecl/hql/hqlerrors.hpp

@@ -507,6 +507,7 @@
 #define HQLERR_CacheMissingOriginal             3152
 #define HQLERR_CacheMissingEntry                3153
 #define HQLERR_PotentialAmbiguity               3154
+#define HQLERR_CannotDefineFunctionFunction     3155
 
 #define HQLERR_DedupFieldNotFound_Text          "Field removed from dedup could not be found"
 #define HQLERR_CycleWithModuleDefinition_Text   "Module definition contains an illegal cycle/recursive definition %s"
@@ -555,6 +556,7 @@
 #define HQLERR_CacheMissingOriginal_Text        "Cannot find original for cache entry '%s'"
 #define HQLERR_CacheMissingEntry_Text           "Cannot process cache entry '%s'"
 #define HQLERR_PotentialAmbiguity_Text          "INTERNAL: Mapping introduces potential ambiguity into expression - please report issue"
+#define HQLERR_CannotDefineFunctionFunction_Text "Cannot define a function that returns a function"
 
 /* parser error */
 #define ERR_PARSER_CANNOTRECOVER    3005  /* The parser can not recover from previous error(s) */

+ 6 - 0
ecl/hql/hqlgram2.cpp

@@ -9655,6 +9655,12 @@ void HqlGram::doDefineSymbol(DefineIdSt * defineid, IHqlExpression * _expr, IHql
             targetScope = activeScope.privateScope;
         }
     }
+    if (isParametered && expr->isFunction())
+    {
+        expr.setown(createNullExpr(expr->queryType()->queryChildType()));
+        reportError(HQLERR_CannotDefineFunctionFunction, idattr.pos, HQLERR_CannotDefineFunctionFunction_Text);
+    }
+
     OwnedHqlExpr normalized = normalizeFunctionExpression(defineid, expr, failure, isParametered, activeScope.activeParameters, activeScope.createDefaults(), modifiers);
     defineSymbolInScope(targetScope, defineid, normalized, idattr, assignPos, semiColonPos);
 

+ 17 - 0
ecl/regress/dlingle1.ecl

@@ -0,0 +1,17 @@
+EXPORT Functions := MODULE
+
+    EXPORT fn_AccountStatus_sort_order(STRING status) := FUNCTION
+           fn_AccountStatus_sort_order :=   CASE(status,
+                                                 'OVERDUE'         => 1,
+                                                 'CURRENT'          => 2,
+                                                 'CLOSED'  => 3,
+                                                 999);
+        RETURN fn_AccountStatus_sort_order;
+    END;
+
+    EXPORT fn_AccountStatus_sort_order2(STRING status) := FUNCTION
+        RETURN fn_AccountStatus_sort_order;
+    END;
+
+END; // module.
+