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

reduce -n returns an IncompatiblePathAccess error #4759

Closed
rgwood opened this issue Mar 7, 2022 · 3 comments · Fixed by #4791
Closed

reduce -n returns an IncompatiblePathAccess error #4759

rgwood opened this issue Mar 7, 2022 · 3 comments · Fixed by #4791
Labels
🐛 bug Something isn't working
Milestone

Comments

@rgwood
Copy link
Contributor

rgwood commented Mar 7, 2022

Describe the bug

Simple uses of reduce --numbered (-n) return an "IncompatiblePathAccess" error.

How to reproduce

〉[1 2 3] | reduce -n {|it, acc| $acc.item + $it.item }
╭───────┬──────────────────────────────────────────────────────────────────╮
│ index │ 2                                                                │
│ item  │ IncompatiblePathAccess("error", Span { start: 5905, end: 5909 }) │
╰───────┴──────────────────────────────────────────────────────────────────╯

Or, using this example from the book (slightly simplified):

〉[3 8 4] | reduce -n {|it, acc| $acc.item + $it.index * $it.item }
╭───────┬──────────────────────────────────────────────────────────────────╮
│ index │ 2                                                                │
│ item  │ IncompatiblePathAccess("error", Span { start: 5958, end: 5962 }) │
╰───────┴──────────────────────────────────────────────────────────────────╯

Expected behavior

I expected nu to return an integer, not an error.

Screenshots

No response

Configuration

key value
version 0.59.1
branch main
short_commit 69fd777
commit_hash 69fd777
commit_date 2022-03-06 00:55:37 +00:00
build_os windows-x86_64
rust_version rustc 1.59.0 (9d1b2106e 2022-02-23)
rust_channel stable-x86_64-pc-windows-msvc
cargo_version cargo 1.59.0 (49d8809dc 2022-02-10)
pkg_version 0.59.1
build_time 2022-03-05 20:45:25 -08:00
build_rust_channel debug
features default, which
installed_plugins

Additional context

I noticed this when trying to upgrade this example in the book for engine-q block syntax. A comment in the example links to this issue which was closed; might be related?

@fdncred fdncred added the 🐛 bug Something isn't working label Mar 7, 2022
@hustcer
Copy link
Contributor

hustcer commented Mar 7, 2022

It’s a simple and fundamental usage and I think we should fix it in v0.60

@hustcer hustcer added the 0.60 label Mar 7, 2022
@hustcer hustcer added this to the v0.60.0 milestone Mar 7, 2022
@hustcer
Copy link
Contributor

hustcer commented Mar 9, 2022

Seems still not work well? @jntrnr
$> [1 2 3] | reduce -n {|it, acc| $acc.item + $it.item }

Error: nu::shell::incompatible_path_access (link)

  × Data cannot be accessed with a cell path
   ╭─[entry #8:1:1]
 1 │ [1 2 3] | reduce -n {|it, acc| $acc.item + $it.item }
   ·                                     ──┬─
   ·                                       ╰── int doesn't support cell paths
   ╰────

@hustcer
Copy link
Contributor

hustcer commented Mar 9, 2022

This works now:
[1 2 3] | reduce -n {|it, acc| $acc + $it.item }
[3 8 4] | reduce -n {|it, acc| $acc + $it.index * $it.item }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants