From 5ed2a60bec932e3cca4c6c4dd12e3a1e4077463e Mon Sep 17 00:00:00 2001 From: George Vasiliades <1221374+Poseidonas@users.noreply.github.com> Date: Sun, 23 Aug 2026 13:13:37 +0300 Subject: [PATCH] fix(oop): assign the return value to the method name in Capacity In ST a method returns by assigning to its own name. Capacity computes the percentage into the protected _capacity member and stops there, so the method returns 0 to its caller. program.st reads that return value: capacity_percentage := tank.Capacity(currentVolume := current_volume); and the exercise text asks for "Capacity : REAL that returns a real with the percentage of capacity of the volume of the tank", so the exercise as shipped does not do what it describes. The member assignment is kept and the return added on top, which is the shape GetState already uses in ValveBase.st: GetState := ValveState#Open; _state := GetState; Reported in #38. --- .../exercises/4_inheritance_complex_valve/src/TankWithVolume.st | 1 + 06_oop_in_st/exercises/solution/src/TankWithVolume.st | 1 + 2 files changed, 2 insertions(+) diff --git a/06_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st b/06_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st index 69b53e7..5546e55 100644 --- a/06_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st +++ b/06_oop_in_st/exercises/4_inheritance_complex_valve/src/TankWithVolume.st @@ -21,6 +21,7 @@ NAMESPACE FluidHandlingClass currentVolume : REAL; END_VAR _capacity := (currentVolume / volume) * 100; + Capacity := _capacity; END_METHOD METHOD PUBLIC OpenInlet diff --git a/06_oop_in_st/exercises/solution/src/TankWithVolume.st b/06_oop_in_st/exercises/solution/src/TankWithVolume.st index eae50f3..1a5b9bb 100644 --- a/06_oop_in_st/exercises/solution/src/TankWithVolume.st +++ b/06_oop_in_st/exercises/solution/src/TankWithVolume.st @@ -19,6 +19,7 @@ NAMESPACE FluidHandlingInterfaces currentVolume : REAL; END_VAR _capacity := (currentVolume / volume) * 100; + Capacity := _capacity; END_METHOD METHOD PUBLIC OpenInlet