> **Describe the bug**
> In if-endif block:
> If TRUE, both `:fini` and `fini` work;
> if FALSE, `:fini` works, but not `fini` - `E117: Missing :endif`.
>
> Seems this only happens with `fini`; other Ex commands work well.
>
> **To Reproduce**
>
> vim9script
> if 0
> echo ":: if-block"
> fini
> endif
> echo ":: Finally"
This behavior is documented: help vim9-discovery
This is not ideal, but it's hard to make this work predictably.
Keep in mind that "finish" is a bit of a weird thing. You never see
that in a C or Java file. Why would you want the file to continue but
not use it?
A more realistic example is when defining a function in two variants:
if condition
def TheFunc()
... solution A
enddef
else
def TheFunc()
... solution B
enddef
endif
It has the same problem: in the discovery phase evaluating "condition"
may not work. It might be possible to do when it is a constant or uses
"has('feature')". Defenitely not if it calls a function, since that
might have side effects.
Now, the question is if we should evaluate "condition" in the discovery
phase, and what to do if it's not a constant? This may lead to
unpredictable behavior. I haven't found a good choice yet.
For now, let's approach it as a normal code file, and ignore those
conditions, parse all the lines. Since it only looks at the start of
the line, you can make a workaround like:
if condition | def TheFunction()
... solution A
else | def TheFunction()
... solution B
endif
This doesn't work, since the functions are not found and won't be
compiled in the next phase.
Not sure if there is any solution in this direction. The alternative
would be to only compile a function once it is called. You would get
any errors only then, not when defining the function. We would need to
fall back to this if we can't make the discovery phase work.
--
"Hit any key to continue" it said, but nothing happened after F sharp.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///