瀏覽代碼

Merge pull request #11165 from ghalliday/issue19685

HPCC-19685 Ensure dummy lookup context created after dummy parse context

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 7 年之前
父節點
當前提交
f0664fcdca
共有 2 個文件被更改,包括 11 次插入5 次删除
  1. 2 2
      ecl/hql/hqlexpr.cpp
  2. 9 3
      ecl/hql/hqlexpr.hpp

+ 2 - 2
ecl/hql/hqlexpr.cpp

@@ -10122,14 +10122,14 @@ IHqlScope * CHqlForwardScope::queryResolvedScope(HqlLookupContext * context)
         //But currently painful in one context, so allow it to be omitted.
         Owned<IErrorReceiver> errorReporter = createThrowingErrorReceiver();
         HqlDummyLookupContext localCtx(errorReporter);
-        HqlLookupContext * activeContext = context ? context : &localCtx;
+        HqlLookupContext & activeContext = context ? *context : localCtx.ctx();
         HqlExprArray syms;
         getSymbols(syms);
         syms.sort(compareSymbolsByName);            // Make errors consistent
         ForEachItemIn(i, syms)
         {
             IIdAtom * cur = syms.item(i).queryId();
-            ::Release(lookupSymbol(cur, LSFsharedOK, *activeContext));
+            ::Release(lookupSymbol(cur, LSFsharedOK, activeContext));
             //Could have been fully resolved while looking up a symbol!
             if (resolvedAll)
                 return resolved;

+ 9 - 3
ecl/hql/hqlexpr.hpp

@@ -1041,14 +1041,20 @@ public:
     HqlLookupContext * container = nullptr;
 };
 
-class HqlDummyLookupContext : public HqlLookupContext
+
+//This is not derived from HqlLookupContext to ensure that dummyCtx is created before the HqlLookupContext
+class HqlDummyLookupContext
 {
 public:
-    //Potentially problematic - dummyCtx not created at the point the constructor is called.
-    HqlDummyLookupContext(IErrorReceiver * _errs) : HqlLookupContext(dummyCtx, _errs) {}
+    HqlDummyLookupContext(IErrorReceiver * _errs) : lookupCtx(dummyCtx, _errs) {}
+
+    HqlLookupContext & ctx() { return lookupCtx; }
+    operator HqlLookupContext & () { return lookupCtx; } // implicit cast to a HqlLookupContext
 
 private:
+    // construction order is significant
     HqlDummyParseContext dummyCtx;
+    HqlLookupContext lookupCtx;
 };
 
 enum