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

Empty case is valid but unreachable #8624

Open
zanchey opened this issue Jan 9, 2022 · 1 comment
Open

Empty case is valid but unreachable #8624

zanchey opened this issue Jan 9, 2022 · 1 comment
Labels
Milestone

Comments

@zanchey
Copy link
Member

zanchey commented Jan 9, 2022

The documentation says this is valid syntax, and indeed it is:

switch $foo
    case
        echo Hello
end

However, the case without an argument is unreachable. A parameter to switch that expands to nothing is equivalent to the empty string (per https://github.com/fish-shell/fish-shell/blob/master/src/parse_execution.cpp#L534-L539).

Should case without an argument be a default (equivalent to case '*') or an error? Or should it be left alone?

@zanchey zanchey added the RFC label Jan 9, 2022
@zanchey zanchey added this to the fish-future milestone Jan 9, 2022
@faho
Copy link
Member

faho commented Jan 9, 2022

I'd probably make a literal empty case error out and leave the commandline incomplete. As it stands you can type the example interactively, and it looks like it works.

Now, case with an empty expansion is another case (hahaha), but there it's probably expected that it won't match. E.g.

set -l cases # empty

switch $foo
    case foo
        echo foo
    case $cases
        # unreachable!
end

This seems to be expected and useful (because the variable also could be non-empty), while a literal empty case is just nothing.

This follows switch, which also needs an argument - it's a syntax error otherwise!

@pltan pltan mentioned this issue Apr 22, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants