Skip to content

Commit

Permalink
Merge pull request hpcc-systems#19110 from ghalliday/issue32654
Browse files Browse the repository at this point in the history
HPCC-32654 Fix crash in eclcc for mismatched functions in PROJECT(module, interface)

Reviewed-By: Dan S. Camper <dan.camper@lexisnexisrisk.com>
Merged-by: Gavin Halliday <ghalliday@hpccsystems.com>
  • Loading branch information
ghalliday authored Sep 19, 2024
2 parents f3fd9ec + 98cd3c1 commit df91760
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ecl/hql/hqlexpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11028,7 +11028,9 @@ IHqlExpression *CHqlDelayedCall::clone(HqlExprArray &newkids)

IHqlExpression * CHqlDelayedCall::makeDelayedCall(IHqlExpression * _funcdef, HqlExprArray &operands)
{
ITypeInfo * returnType = _funcdef->queryType()->queryChildType();
ITypeInfo * funcType = _funcdef->queryType();
assertex(funcType->getTypeCode() == type_function);
ITypeInfo * returnType = funcType->queryChildType();
CHqlDelayedCall * ret;
switch (returnType->getTypeCode())
{
Expand Down
24 changes: 24 additions & 0 deletions ecl/hql/hqlgram2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3638,6 +3638,30 @@ IHqlExpression * HqlGram::implementInterfaceFromModule(const attribute & modpos,
{
HqlExprArray parameters;
bool isParametered = extractSymbolParameters(parameters, &baseSym);
if (baseSym.isFunction() != match->isFunction())
{
if (isParametered)
{
//Convert the value to a function definition - the parameters will be ignored
IHqlExpression * formals = queryFunctionParameters(&baseSym);
IHqlExpression * defaults = queryFunctionDefaults(&baseSym);
OwnedHqlExpr funcdef = createFunctionDefinition(id, LINK(match->queryBody()), LINK(formals), LINK(defaults), NULL);
match.setown(match->cloneAllAnnotations(funcdef));
}
else
{
//Convert a function into a value - possible if all parameters (including none) have default values
if (!allParametersHaveDefaults(match))
{
reportError(ERR_EXPECTED_ATTRIBUTE, ipos, "Symbol %s is defined as a value in the base scope, but a function with non-default parameters in the interface", str(id));
}
else
{
HqlExprArray actuals;
match.setown(createBoundFunction(nullptr, match, actuals, nullptr, false));
}
}
}

checkDerivedCompatible(id, newScopeExpr, match, isParametered, parameters, modpos);
newScope->defineSymbol(LINK(match));
Expand Down
50 changes: 50 additions & 0 deletions ecl/regress/iproject.ecl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2024 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.
############################################################################## */

myModule := MODULE

EXPORT value1 := 100;
EXPORT value2 := 200;
EXPORT value3(unsigned x = 10) := 300;
EXPORT value4() := 400;

END;

myInterface := INTERFACE

EXPORT value1 := 0;
EXPORT value2(unsigned unknown) := 0;
EXPORT value3 := 0;
EXPORT value4() := 0;

END;



display(myInterface x) := FUNCTION
RETURN
ORDERED(
OUTPUT(x.value1);
OUTPUT(x.value2(99999));
OUTPUT(x.value3);
OUTPUT(x.value4());
);
END;


mappedModule := PROJECT(myModule, myInterface);
display(mappedModule);
50 changes: 50 additions & 0 deletions ecl/regress/iproject_err.ecl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*##############################################################################
HPCC SYSTEMS software Copyright (C) 2024 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.
############################################################################## */

myModule := MODULE

EXPORT value1 := 100;
EXPORT value2 := 200;
EXPORT value3(unsigned i) := 300; // invalid - no default value supplied
EXPORT value4() := 400;

END;

myInterface := INTERFACE

EXPORT value1 := 0;
EXPORT value2() := 0;
EXPORT value3 := 0;
EXPORT value4() := 0;

END;



display(myInterface x) := FUNCTION
RETURN
ORDERED(
OUTPUT(x.value1);
OUTPUT(x.value2());
OUTPUT(x.value3);
OUTPUT(x.value4());
);
END;


mappedModule := PROJECT(myModule, myInterface);
display(mappedModule);

0 comments on commit df91760

Please sign in to comment.