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 zcompile error with zsh 5.4 #443

Closed
wants to merge 1 commit into from
Closed

Fix zcompile error with zsh 5.4 #443

wants to merge 1 commit into from

Conversation

ericbn
Copy link

@ericbn ericbn commented Sep 11, 2017

Error is:

$ zcompile highlighters/main/test-data/function.zsh
zsh: defining function based on alias `ls'
zsh: parse error near `()'
zcompile: can't read file: highlighters/main/test-data/function.zsh

View Incompatibilities since 5.3.1 in https://github.com/zsh-users/zsh/blob/bb218704d27bcca9aa4426296dcd5c13d58b330a/README

Error is:

    $ zcompile highlighters/main/test-data/function.zsh
    zsh: defining function based on alias `ls'
    zsh: parse error near `()'
    zcompile: can't read file: highlighters/main/test-data/function.zsh

View `Incompatibilities since 5.3.1` in
https://github.com/zsh-users/zsh/blob/bb218704d27bcca9aa4426296dcd5c13d58b330a/README
@danielshahaf
Copy link
Member

I'm aware of the upstream change, thanks, see 9523d6d.

What I don't understand is why this is needed in the first place. z-sy-h does not alias ls anywhere, and in fact, it goes into some trouble to ensure that it won't be affected by any alias ls=... that .zshrc might be doing:

# First of all, ensure predictable parsing.
zsh_highlight__aliases=`builtin alias -Lm '[^+]*'`
# In zsh <= 5.2, `alias -L` emits aliases that begin with a plus sign ('alias -- +foo=42')
# them without a '--' guard, so they don't round trip.
#
# Hence, we exclude them from unaliasing:
builtin unalias -m '[^+]*'

And separately, what's the use-case for zcompiling test-data files (!)?

@ericbn
Copy link
Author

ericbn commented Sep 11, 2017

@danielshahaf, good points.

Should we change the test to do only:

BUFFER='cd;ls'

expected_region_highlight=(
  "1 2 builtin" # cd
  "4 5 command" # ls
)

without the functions? There's also a comment at the end of the test I quite don't understand:

# ... cd() and ls() should still be a functions
# when _zsh_highlight runs.  Leaving the wrapper functions is harmless.

And it makes no sense to compile the test-data. I'm just compiling everything under highlighters. I should fix that on my side...

danielshahaf added a commit that referenced this pull request Sep 11, 2017
The functions can remain defined because, nowadays, the test harness
runs each test in a subshell; but that's a well-known property of the
test harness so need not be mentioned explicitly.

Inspired by discussion on issue #443.
@danielshahaf
Copy link
Member

No, we shouldn't. The whole point of the test is to test that a function that shadows a builtin (or a command) is highlighted as a function.

I've fixed the comment in 5436d3e, thanks for pointing it out.

Does this address everything?

@ericbn
Copy link
Author

ericbn commented Sep 11, 2017

Does this address everything?

Isn't function ls preferred over ls(), to address the issue when ls is already an alias...?

@danielshahaf
Copy link
Member

Aliases typically change the default behaviour (e.g., alias ls='ls -F') in ways that may break scripts. The right answer is for .zshrc aliases not to be in effect while running the test suite.

That's already the case when the test suite is launched by make test.

See also #444.

@danielshahaf
Copy link
Member

Aliases typically change the default behaviour (e.g., alias ls='ls -F') in ways that may break scripts.

To be clear here, I refer to scripts that run ls, e.g., if ls | grep '^foo$'; then …, with no functions involved.

@ericbn
Copy link
Author

ericbn commented Sep 11, 2017

Sounds good. Closing this. Not compiling the files under test-data works for me, and is also an optimization. Thank you!

@ericbn ericbn closed this Sep 11, 2017
@ericbn ericbn deleted the zcompile branch September 11, 2017 19:31
ericbn added a commit to zimfw/zimfw that referenced this pull request Sep 11, 2017
for syntax-highlighting submodule. See discussion on
zsh-users/zsh-syntax-highlighting#443

Fixes #205
@danielshahaf
Copy link
Member

You're welcome. Thanks for the report!

brandon-fryslie pushed a commit to brandon-fryslie/zsh-syntax-highlighting that referenced this pull request Dec 21, 2017
The functions can remain defined because, nowadays, the test harness
runs each test in a subshell; but that's a well-known property of the
test harness so need not be mentioned explicitly.

Inspired by discussion on issue zsh-users#443.
ToddMenier pushed a commit to ToddMenier/zimfw that referenced this pull request Dec 26, 2022
for syntax-highlighting submodule. See discussion on
zsh-users/zsh-syntax-highlighting#443

Fixes #205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants