Skip to content

Commit

Permalink
fix: chained memoized calls (#987)
Browse files Browse the repository at this point in the history
- fix: chains of calls to member functions

---------

Co-authored-by: megalinter-bot <[email protected]>
  • Loading branch information
WinPlay02 and megalinter-bot authored Apr 5, 2024
1 parent c064e0e commit df89291
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1031,10 +1031,12 @@ export class SafeDsPythonGenerator {
containsOptionalArgs
? this.generatePlainCall(expression, sortedArgs, frame)
: isSdsMemberAccess(expression.receiver) && isSdsCall(expression.receiver.receiver)
? expandTracedToNode(expression.receiver)`${this.generateExpression(
expression.receiver.receiver.receiver,
frame,
)}.${this.generateExpression(expression.receiver.member!, frame)}`
? isSdsMemberAccess(expression.receiver.receiver.receiver)
? this.getClassQualifiedNameForMember(<SdsClassMember>callable)
: expandTracedToNode(expression.receiver)`${this.generateExpression(
expression.receiver.receiver.receiver,
frame,
)}.${this.generateExpression(expression.receiver.member!, frame)}`
: isSdsMemberAccess(expression.receiver)
? this.getClassQualifiedNameForMember(<SdsClassMember>callable)
: this.generateExpression(expression.receiver, frame)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Imports ----------------------------------------------------------------------

import safeds_runner
from safeds.data.image.containers import Image
from safeds.data.tabular.containers import Column, Table
from tests.generator.memberAccessWithRunnerIntegration import C, f, factory, factoryNested, g, h, Outer
from typing import Any, TypeVar
Expand Down Expand Up @@ -34,7 +35,16 @@ def test():
safeds_runner.save_placeholder('v', v)
d = safeds_runner.memoized_call("safeds.data.tabular.containers.Column.plot_histogram", Column.plot_histogram, [v], [])
safeds_runner.save_placeholder('d', d)
p = safeds_runner.memoized_call("safeds.data.tabular.containers.Column.plot_histogram", Column.plot_histogram, [safeds_runner.memoized_call("safeds.data.tabular.containers.Table.get_column", Table.get_column, [a, 'b'], [])], [])
safeds_runner.save_placeholder('p', p)
r = safeds_runner.memoized_call("safeds.data.image.containers.Image.flip_vertically", Image.flip_vertically, [safeds_runner.memoized_call("safeds.data.tabular.containers.Column.plot_histogram", Column.plot_histogram, [safeds_runner.memoized_call("safeds.data.tabular.containers.Table.get_column", Table.get_column, [a, 'b'], [])], [])], [])
safeds_runner.save_placeholder('r', r)
q = safeds_runner.memoized_call("safeds.data.image.containers.Image.adjust_contrast", Image.adjust_contrast, [safeds_runner.memoized_call("safeds.data.image.containers.Image.flip_vertically", Image.flip_vertically, [safeds_runner.memoized_call("safeds.data.tabular.containers.Column.plot_histogram", Column.plot_histogram, [safeds_runner.memoized_call("safeds.data.tabular.containers.Table.get_column", Table.get_column, [a, 'b'], [])], [])], []), 1.2], [])
safeds_runner.save_placeholder('q', q)
f(d)
f(p)
f(r)
f(q)
f(safeds_runner.memoized_call("tests.generator.memberAccessWithRunnerIntegration.Outer.Nested.f", Outer.Nested.f, [], []))
nestedInstance = safeds_runner.memoized_call("tests.generator.memberAccessWithRunnerIntegration.factoryNested", factoryNested, [], [])
safeds_runner.save_placeholder('nestedInstance', nestedInstance)
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ pipeline test {
val a = Table.fromCsvFile("abc.csv");
val v = a.getColumn("b");
val d = v.plotHistogram();
val p = a.getColumn("b").plotHistogram();
val r = a.getColumn("b").plotHistogram().flipVertically();
val q = a.getColumn("b").plotHistogram().flipVertically().adjustContrast(1.2);
f(d);
f(p);
f(r);
f(q);
f(Outer.Nested.f());
val nestedInstance = factoryNested();
val nestedResult = nestedInstance.g();
Expand Down

0 comments on commit df89291

Please sign in to comment.