-
Notifications
You must be signed in to change notification settings - Fork 4
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
Typeset built-in for functions #318
Conversation
WalkthroughThe changes introduce new functionality to the Changes
Poem
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (3)
- yash-builtin/src/typeset.rs (6 hunks)
- yash-builtin/src/typeset/print_functions.rs (1 hunks)
- yash-builtin/src/typeset/set_functions.rs (1 hunks)
Additional comments: 11
yash-builtin/src/typeset/set_functions.rs (2)
23-69: The
execute
method is well-structured and handles different cases for function attributes. It collects errors in a vector and returns them if any exist, otherwise it returns an empty string. This is a good approach for error handling.161-174: The tests are comprehensive and cover all the scenarios for the
execute
method. They test making existing functions read-only, unsetting read-only attributes, and handling non-existing functions. The use of assertions ensures the expected behavior.yash-builtin/src/typeset/print_functions.rs (4)
1-15: Ensure that the license information is updated correctly and is consistent with the rest of the project.
22-49: The
execute
method in thePrintFunctions
struct is well implemented. It handles both the cases where specific functions are to be printed and where all functions are to be printed. It also correctly handles errors when a function to be printed does not exist.52-72: The helper function
print_one
correctly filters functions based on attributes and formats the function for printing. It also handles the case where the function is read-only.74-260: The tests cover a wide range of scenarios and seem to be well implemented. They test the printing of one function, multiple functions, all functions, quoting of function names, printing of read-only functions, selecting of read-only and non-read-only functions, and handling of non-existing functions.
yash-builtin/src/typeset.rs (5)
256-270: The new
print_functions
module is imported and theFunction
import is added. Ensure that theprint_functions
module is correctly implemented and that theFunction
import is used appropriately in the code.347-359: A new
FunctionAttr
enum is defined with atest
method. This seems to be a good way to handle function attributes. Ensure that thetest
method is correctly implemented and used.490-497: A new
ModifyUnsetFunction
variant is added to theExecuteError
enum. This is a good way to handle errors related to modifying unset functions. Ensure that this new variant is correctly handled in the error handling code.504-510: The
MessageBase
implementation is updated to handle the newModifyUnsetFunction
variant. This is a good way to provide error messages for the new error variant. Ensure that the error message is informative and user-friendly.525-531: A new match arm is added in the
main_annotation
method to handle theModifyUnsetFunction
variant. This is a good way to provide annotations for the new error variant. Ensure that the annotation is informative and user-friendly.
Some(name.origin.clone()); | ||
functions | ||
.define(function) | ||
.unwrap_or_else(|e| unreachable!("{e:?}")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of unwrap_or_else
with unreachable
is risky. If the define
function ever fails, it will cause a panic. Consider handling this error gracefully.
- .unwrap_or_else(|e| unreachable!("{e:?}"));
+ .map_err(|e| errors.push(ExecuteError::FunctionDefineError(name.clone(), e)))?;
Commitable suggestion
[!IMPORTANT]
Carefully review the code before committing. Make sure it correctly replaces the highlighted code, has no missing lines and indentaion issues.
.unwrap_or_else(|e| unreachable!("{e:?}")); | |
.map_err(|e| errors.push(ExecuteError::FunctionDefineError(name.clone(), e)))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of unreachable
is actually safe because it is logically impossible to reach the error case. I added a comment to clarify the situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@magicant Thank you for the clarification. It's important to ensure that the code's behavior is well-documented, especially in cases where certain error conditions are considered unreachable. Your comment helps future developers understand the reasoning behind the use of unreachable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- yash-builtin/src/typeset/set_functions.rs (1 hunks)
Additional comments: 2
yash-builtin/src/typeset/set_functions.rs (2)
21-73: The
execute
method is well-structured and handles errors appropriately. It iterates over the functions and their attributes, modifying theFunctionSet
accordingly. The error handling is comprehensive, covering cases where a function is unset or read-only. The logic seems correct and the code is readable and maintainable.76-178: The tests cover all the main scenarios and edge cases, including making existing functions read-only, unsetting read-only attributes, and handling non-existing functions. The use of
assert_matches
andassert_eq
ensures that the function behavior is as expected. The tests are well-structured and comprehensive.
Summary by CodeRabbit