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 infinite recursion when walking Abstractions #217

Merged
merged 1 commit into from
Jul 18, 2024
Merged
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
7 changes: 6 additions & 1 deletion src/Nixfmt/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@ instance LanguageElement Expression where
)
(Assert _ cond _ body) -> [cond, body]
(If _ expr0 _ expr1 _ expr2) -> [expr0, expr1, expr2]
(Abstraction param _ body) -> [Abstraction param (ann TColon) (Term (Token (ann (Identifier "_")))), body]
-- If the body is just a token, it doesn't have an expression, only walk through the parameter
-- This is also the base case for the result below
(Abstraction param _ (Term (Token _))) -> walkSubprograms param
-- Otherwise, to separate the parameter from the body while keeping it a valid expression,
-- replace the body with just a token. Return the body (a valid expression on its own) separately
(Abstraction param colon body) -> [Abstraction param colon (Term (Token (ann (Identifier "_")))), body]
(Application g a) -> [g, a]
(Operation left _ right) -> [left, right]
(MemberCheck name _ sels) -> name : (sels >>= walkSubprograms)
Expand Down