fix(oop): assign the return value to the method name in Capacity - #40
Open
Poseidonas wants to merge 1 commit into
Open
fix(oop): assign the return value to the method name in Capacity#40Poseidonas wants to merge 1 commit into
Poseidonas wants to merge 1 commit into
Conversation
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 simatic-ax#38.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #38.
Capacitycomputes the percentage into the protected_capacitymember and stops there. In ST a method returns by assigning to its own name, so it hands back0.That return value is read:
and the exercise text asks for:
So
capacity_percentagestays at zero for anyone following the module, which is a confusing thing to meet while learning the language.The member assignment is kept and the return added on top, which is the shape
GetStatealready uses inValveBase.st:Applied in both copies —
exercises/solution/andexercises/4_inheritance_complex_valve/.Two things I looked at and left alone
0_basic_valve_class/src/ValveBase.stalso has aGetStatethat does not assign to its name, but every method there is;— it is the skeleton the exercise asks the reader to fill in, so it is correct as it stands.TankWithShape.sthas twoVolumeCalculator : REALmethods which assign tovolumerather than to the method name. Here I was not sure what you intend: the slides say the volume is "calculated with a method called VolumeCalculator and the result stored in the property volume", and the only caller ignores the return value:So the body matches the brief and nothing is broken — but then the
: REALreturn type is never used, which is its own small trap for a reader learning how ST methods return. Either addingVolumeCalculator := volume;or dropping the return type would settle it. Happy to do whichever you prefer, in this PR or a separate one.On verification
I have no AX toolchain here, so I did not compile this. What I checked is that the change follows the assignment form already used elsewhere in the module, that the callers listed above do read the value, and that nothing else in module 6 has the same shape — I walked every
METHOD ... : <type>in the module and the only remaining ones are the two described above.