Skip to content

Parser does not detect several syntax errors #360

@chaliy

Description

@chaliy

Description

The bashkit parser does not reject several invalid syntax constructs that real bash rejects as parse errors.

Scope

  • ${%} — invalid braced var sub not rejected
  • {ls; }{ without space not rejected (should be parse error)
  • for i.j in ... — invalid for-loop variable name not rejected
  • export FOO-BAR=foo — invalid variable name in export not rejected
  • local FOO-BAR=foo — invalid variable name in local not rejected
  • echo a(b) — misplaced parentheses not rejected
  • Incomplete command sub $(x — not detected
  • Incomplete backticks — not detected
  • [[ || true ]] — empty clause in [[ not rejected
  • Unterminated single and double quotes not detected
  • Empty while/for/if/else/function bodies not rejected (bash requires at least : or a command)

Repro

# bashkit: no error (wrong)
# bash: syntax error
for i.j in a b c; do echo hi; done

# bashkit: outputs the text (wrong)
# bash: syntax error, exit 2
echo 'unterminated

# bashkit: allows empty body (wrong)
# bash: syntax error near unexpected token 'done'
while false; do
done

Test coverage

  • 11 skipped tests in crates/bashkit/tests/spec_cases/bash/parse-errors.test.sh
  • 5 skipped tests in crates/bashkit/tests/spec_cases/bash/empty-bodies.test.sh

All added in PR #351.

Oils reference: https://github.com/oilshell/oil/blob/master/spec/parse-errors.test.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions