Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generation of static class functions #832

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,12 @@ export class SafeDsPythonGenerator {
): CompositeGeneratorNode {
frame.addImport({ importPath: RUNNER_SERVER_PIPELINE_MANAGER_PACKAGE });
const hiddenParameters = this.getMemoizedCallHiddenParameters(expression, frame);
const memoizedArgs = getParameters(this.nodeMapper.callToCallable(expression)).map(
const callable = this.nodeMapper.callToCallable(expression);
const memoizedArgs = getParameters(callable).map(
(parameter) => this.nodeMapper.callToParameterValue(expression, parameter)!,
);
// For a static function, the thisParam would be the class containing the function. We do not need to generate it in this case
const generateThisParam = !isSdsFunction(callable) || (!callable.isStatic && thisParam);
const containsOptionalArgs = sortedArgs.some((arg) =>
Parameter.isOptional(this.nodeMapper.argumentToParameter(arg)),
);
Expand All @@ -871,7 +874,9 @@ export class SafeDsPythonGenerator {
frame,
)}.${this.generateExpression(expression.receiver.member!, frame)}`
: this.generateExpression(expression.receiver, frame)
}, [${thisParam ? thisParam.append(', ') : ''}${joinTracedToNode(expression.argumentList, 'arguments')(
}, [${generateThisParam ? thisParam : ''}${
generateThisParam && memoizedArgs.length > 0 ? ', ' : ''
}${joinTracedToNode(expression.argumentList, 'arguments')(
memoizedArgs,
(arg) => this.generateExpression(arg, frame),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class C() {

@Pure
@PythonName("k2") fun k(param: Any?) -> result: Boolean

@Impure([ImpurityReason.FileReadFromParameterizedPath("name")])
static fun from_csv_file(name: String) -> c: C
}

@Pure fun factory() -> instance: C?
Expand All @@ -34,4 +37,5 @@ pipeline test {
f(C().i(1));
f(C().j(123));
f(C().k("abc"));
f(C.from_csv_file("abc.csv"));
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ def test():
f(safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C.i", lambda *_ : 1.i(safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C", C, [], [])), [1], []))
f(safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C.j", C.j, [safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C", C, [], []), 123], []))
f(safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C.k2", C.k2, [safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C", C, [], []), 'abc'], []))
f(safeds_runner.server.pipeline_manager.runner_memoized_function_call("tests.generator.memberAccess.C.from_csv_file", C.from_csv_file, ['abc.csv'], [safeds_runner.server.pipeline_manager.runner_filemtime('abc.csv')]))

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading