From f7bde1354d80ea458ac7043ecbf96818d374f7f4 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Thu, 1 May 2025 14:51:30 +0200 Subject: [PATCH] Only count it as a naked invocation at the end of the "file" This is a weird confusion between the "end" and "terminate" token types. "end" is the end of the "line" - a newline or ";". "terminate" is the end of the "file" - like pressing newline interactively or having the file end. So this would count things like `if` and `switch` as a "help" invocation even if followed by a newline, e.g. ```fish if; echo foo ``` and ```fish switch case foo ``` The result of that was that a naked "if" in a script file isn't an error, but doesn't start a block either, so if you complete the block it would count the "end" as superfluous, which sends you on a bit of a hunt to figure out where the block start is missing. --- src/ast.rs | 3 +-- tests/checks/switch.fish | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 6341aa026..c66d4b2b2 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -3580,8 +3580,7 @@ fn new_decorated_statement(slf: &mut Populator<'_>) -> StatementVariant { let naked_invocation_invokes_help = ![ParseKeyword::Begin, ParseKeyword::End].contains(&self.peek_token(0).keyword); if naked_invocation_invokes_help - && [ParseTokenType::end, ParseTokenType::terminate] - .contains(&self.peek_token(1).typ) + && [ParseTokenType::terminate].contains(&self.peek_token(1).typ) { return new_decorated_statement(self); } diff --git a/tests/checks/switch.fish b/tests/checks/switch.fish index 7e1d56b10..ed5feb38e 100644 --- a/tests/checks/switch.fish +++ b/tests/checks/switch.fish @@ -66,9 +66,9 @@ switch echo banana end ' -#CHECKERR: fish: 'case' builtin not inside of switch block -#CHECKERR: case a -#CHECKERR: ^~~^ +# CHECKERR: fish: Expected a string, but found end of the statement +# CHECKERR: switch +# CHECKERR: ^ set smurf green