mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.1k stars 336 forks source link

syntax: add error message for herestrings in POSIX mode #891

Closed hristiy4n closed 2 years ago

hristiy4n commented 2 years ago

Fixes #881

hristiy4n commented 2 years ago

Please add a test case for foo << < bar as well - I think your logic will incorrectly fire in that case too, as you just look at p.tok.

A better solution might be to always tokenize <<< as a single token, and then error if the parser encounters the token in posix mode.

You are right, foo << < bar will not throw the correct error message with this logic.

I saw that lexer.go:506 doesn't return <<< when p.lang != LangPOSIX. I didn't remove the condition as I didn't want to break any existing functionality. Removing this condition and always having <<< as a token sounds like a better solution.