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

Can't count array elements #114

Closed
BatmanAoD opened this Issue May 23, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@BatmanAoD
Contributor

BatmanAoD commented May 23, 2018

I'm not sure if this is a bug or something that's just not implemented yet:

osh$ arr=(foo)
osh$ echo ${#arr[@]}
Traceback (most recent call last):
  File "/home/aucdeveloper/personal_projects/oil/bin/osh", line 622, in <module>
    main(sys.argv)
  File "/home/aucdeveloper/personal_projects/oil/bin/osh", line 600, in main
    sys.exit(AppBundleMain(argv))
  File "/home/aucdeveloper/personal_projects/oil/bin/osh", line 576, in AppBundleMain
    status = OshMain(argv0, main_argv, login_shell)
  File "/home/aucdeveloper/personal_projects/oil/bin/osh", line 306, in OshMain
    return InteractiveLoop(opts, ex, c_parser, w_parser, line_reader)
  File "/home/aucdeveloper/personal_projects/oil/bin/osh", line 130, in InteractiveLoop
    status, is_control_flow = ex.ExecuteAndCatch(node)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/cmd_exec.py", line 1176, in ExecuteAndCatch
    status = self._Execute(node, fork_external=fork_external)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/cmd_exec.py", line 1148, in _Execute
    status, check_errexit = self._Dispatch(node, fork_external)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/cmd_exec.py", line 885, in _Dispatch
    status = self._ExecuteList(node.children)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/cmd_exec.py", line 1169, in _ExecuteList
    status = self._Execute(child)  # last status wins
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/cmd_exec.py", line 1148, in _Execute
    status, check_errexit = self._Dispatch(node, fork_external)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/cmd_exec.py", line 671, in _Dispatch
    argv = self.word_ev.EvalWordSequence(words)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/word_eval.py", line 905, in EvalWordSequence
    return self._EvalWordSequence(words)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/word_eval.py", line 878, in _EvalWordSequence
    self._EvalWordToParts(w, False, part_vals)  # not double quoted
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/word_eval.py", line 705, in _EvalWordToParts
    self._EvalWordPart(p, part_vals, quoted=quoted)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/word_eval.py", line 677, in _EvalWordPart
    self._EvalBracedVarSub(part, part_vals, quoted)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/word_eval.py", line 590, in _EvalBracedVarSub
    val = self._DecayArray(val)
  File "/home/aucdeveloper/personal_projects/oil/bin/../core/word_eval.py", line 372, in _DecayArray
    assert val.tag == value_e.StrArray, val
AssertionError: (Str s:1)

In any case, is there a working way to count arrays in osh yet?

@BatmanAoD

This comment has been minimized.

Show comment
Hide comment
@BatmanAoD

BatmanAoD May 23, 2018

Contributor

It does not work with [*] either.

Contributor

BatmanAoD commented May 23, 2018

It does not work with [*] either.

@andychu

This comment has been minimized.

Show comment
Hide comment
@andychu

andychu May 24, 2018

Contributor

I confirmed that this is a bug. Thanks for the report!

I thought there was a spec test for the length of arrays but apparently not.

Contributor

andychu commented May 24, 2018

I confirmed that this is a bug. Thanks for the report!

I thought there was a spec test for the length of arrays but apparently not.

andychu pushed a commit that referenced this issue May 25, 2018

@andychu

This comment has been minimized.

Show comment
Hide comment
@andychu

andychu May 25, 2018

Contributor

Fixed, thanks for the report!

Contributor

andychu commented May 25, 2018

Fixed, thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment