Skip to content

Commit 05fdcff

Browse files
authored
Add getFunction to the Context (#338)
Fixes #335 by adding a getFunction() method to the Context class which goes up the parent context tree until it gets to the Library and is able to execute getFunction. This fixes the issue of an overloaded function that has the same name as one of its arguments and calls itself (or another overload). The broad context.get() method was being used to get the possible FunctionDefs was returning the first thing that matches the name of the function. So it was ending up with the value of the argument passed in which had the same name. Tests are included that replicate this issue with multiple modes of execution. This PR also updates the cql-to-elm version for test data generation to 3.22.0 and updates the translator options to roughly match the options used by MADiE. Included (squashed) commits: * initial adding of test for fluent overloading issue * updated cql-to-elm to 3.22.0 and added some translator options that MADiE uses * Added test for overloaded functions calling themselves * resolved npm audit concern with babel and fixed prettier issue with test-data file * reworked test to have an argument name matching the overloaded function name. fixed issue by adding getFunction to Context * add missing newline to package-lock.json that npm insists on making * added info on translator settings. cql fix for ProperIncludedIn test. re-built test, fixing some post rebase stuff. added new test library to prettier ignore * renamed new tests. rebuilt spec-test data with new translator and added workaround for ProperIncludedIn null test
1 parent 5692931 commit 05fdcff

53 files changed

Lines changed: 211759 additions & 56442 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ test/elm/library/Common.js
1313
test/elm/library/Common2.js
1414
test/elm/library/data-with-namespace.js
1515
test/elm/message/Included.js
16+
test/elm/reusable/FluentFunctionsOverloadCallingSelf.js

examples/browser/cql4browsers.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6876,7 +6876,7 @@ class FunctionRef extends expression_1.Expression {
68766876
child_ctx = libCtx ? libCtx.childContext() : undefined;
68776877
}
68786878
else {
6879-
functionDefs = ctx.get(this.name);
6879+
functionDefs = ctx.getFunction(this.name);
68806880
child_ctx = ctx.childContext();
68816881
}
68826882
const args = await this.execArgs(ctx);
@@ -8082,6 +8082,9 @@ class Context {
80828082
getConcept(name) {
80838083
return this.parent && this.parent.getConcept(name);
80848084
}
8085+
getFunction(name) {
8086+
return this.parent && this.parent.getFunction(name);
8087+
}
80858088
get(identifier) {
80868089
// Check for undefined because if its null, we actually *do* want to return null (rather than
80878090
// looking at parent), but if it's really undefined, *then* look at the parent

src/elm/reusable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class FunctionRef extends Expression {
7474
const libCtx = ctx.getLibraryContext(this.library);
7575
child_ctx = libCtx ? libCtx.childContext() : undefined;
7676
} else {
77-
functionDefs = ctx.get(this.name);
77+
functionDefs = ctx.getFunction(this.name);
7878
child_ctx = ctx.childContext();
7979
}
8080
const args = await this.execArgs(ctx);

src/runtime/context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export class Context {
155155
return this.parent && this.parent.getConcept(name);
156156
}
157157

158+
getFunction(name: string) {
159+
return this.parent && this.parent.getFunction(name);
160+
}
161+
158162
get(identifier: string): any {
159163
// Check for undefined because if its null, we actually *do* want to return null (rather than
160164
// looking at parent), but if it's really undefined, *then* look at the parent

0 commit comments

Comments
 (0)