Calculations resulting in, or containing decimals in `ion-math` and `$(( ))` result in panic within the interactive shell but not when executed from a script
bug: expressions resulting in decimals or containing a .
will panic within ion-math
and $(( ))
. seemingly only in the interactive shell or within the ion-math
builtin, attempting the calculation within a process expansion (echo $( $(( 2 / 3 )) )
) results in a slightly different error message than if the calculation is attempted normally from within a script.
expect: result of expression
related: none
code: input
echo $(( 3 / 4 ))
echo $(( 1 / 2 ))
echo $(( 2 / 3 ))
echo $(( 34 / 645 ))
echo $(( 144 / 96 ))
echo $(( . ))
echo $(( 3.0 ))
expect: output
0
0
0
0
1
ion: bad floating point constant
3.0
when evaluated within a subshell however, it does not panic and simply returns the following:
ion-sh# echo $( $(( 2 / 4 )) )
ion: expansion error: Could not expand subprocess: syntax error: syntax error: unterminated arithmetic subexpression
when run from a shell script, though, it behaves as expected
echo $(( 3 / 4 ))
echo $(( 1 / 2 ))
echo $(( 2 / 3 ))
echo $(( 34 / 645 ))
echo $(( 144 / 96 ))
echo $(( 3.0 ))
output
0
0
0
0
1
./bug.ion: line 6: 3.0 : syntax error: invalid arithmetic operator (error token is ".0 ")
actual: output (same for all)
thread 'main' panicked at 'attempted to leave type `context::Context` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
zsh: abort (core dumped) ion
running ion with RUST_BACKTRACE=1
results in the following: (same for all)
thread 'main' panicked at 'attempted to leave type `context::Context` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
zsh: abort (core dumped) RUST_BACKTRACE=1 ion
running ion with RUST_BACKTRACE=full
results in the following:
ion# echo $(( 3 / 4 ))
thread 'main' panicked at 'attempted to leave type `context::Context` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
stack backtrace:
0: rust_begin_unwind
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
1: core::panicking::panic_fmt
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
2: core::panicking::panic
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:50
3: core::mem::uninitialized
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658
4: decimal::dec128::d128::default_context
at /home/alex/.cargo/git/checkouts/decimal-9ef42407b1b3f309/972c854/src/dec128.rs:492
5: decimal::dec128::CTX::__init
at /home/alex/.cargo/git/checkouts/decimal-9ef42407b1b3f309/972c854/src/dec128.rs:28
6: core::ops::function::FnOnce::call_once
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/ops/function.rs:227
7: std::thread::local::lazy::LazyKeyInner<T>::initialize
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:304
8: std::thread::local::fast::Key<T>::try_initialize
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:473
9: std::thread::local::fast::Key<T>::get
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:456
10: decimal::dec128::CTX::__getit
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:183
11: std::thread::local::LocalKey<T>::try_with
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:271
12: std::thread::local::LocalKey<T>::with
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:248
13: decimal::dec128::d128::with_context
at /home/alex/.cargo/git/checkouts/decimal-9ef42407b1b3f309/972c854/src/dec128.rs:500
14: <decimal::dec128::d128 as core::ops::arith::Div>::div
at /home/alex/.cargo/git/checkouts/decimal-9ef42407b1b3f309/972c854/src/dec128.rs:319
15: <calc::value::Value as core::ops::arith::Div>::div
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/value.rs:300
16: calc::parse::t_expr
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/parse.rs:136
17: calc::parse::e_expr
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/parse.rs:91
18: calc::parse::d_expr
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/parse.rs:44
19: calc::parse::parse
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/parse.rs:352
20: calc::eval::{{closure}}
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/lib.rs:17
21: core::result::Result<T,E>::and_then
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/result.rs:708
22: calc::eval
at /home/alex/.cargo/git/checkouts/calc-936413027aef1cfa/c2f9cdd/src/lib.rs:17
23: ion_shell::expansion::ExpanderInternal::expand_arithmetic::{{closure}}::{{closure}}
at ./src/lib/expansion/mod.rs:661
24: ion_shell::memory::IonPool::string::{{closure}}
at ./src/lib/memory.rs:28
25: std::thread::local::LocalKey<T>::try_with
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:272
26: std::thread::local::LocalKey<T>::with
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:248
27: ion_shell::memory::IonPool::string
at ./src/lib/memory.rs:27
28: ion_shell::expansion::ExpanderInternal::expand_arithmetic::{{closure}}
at ./src/lib/expansion/mod.rs:637
29: ion_shell::memory::IonPool::string::{{closure}}
at ./src/lib/memory.rs:28
30: std::thread::local::LocalKey<T>::try_with
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:272
31: std::thread::local::LocalKey<T>::with
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/thread/local.rs:248
32: ion_shell::memory::IonPool::string
at ./src/lib/memory.rs:27
33: ion_shell::expansion::ExpanderInternal::expand_arithmetic
at ./src/lib/expansion/mod.rs:636
34: ion_shell::expansion::ExpanderInternal::expand_single_string_token
at ./src/lib/expansion/mod.rs:445
35: ion_shell::expansion::ExpanderInternal::expand_single_array_token
at ./src/lib/expansion/mod.rs:425
36: ion_shell::expansion::ExpanderInternal::expand_tokens
at ./src/lib/expansion/mod.rs:514
37: ion_shell::expansion::Expander::expand_string
at ./src/lib/expansion/mod.rs:166
38: ion_shell::shell::job::expand_arg
at ./src/lib/shell/job.rs:57
39: ion_shell::shell::job::Job::expand
at ./src/lib/shell/job.rs:24
40: ion_shell::expansion::pipelines::PipeItem<ion_shell::shell::job::Job>::expand
at ./src/lib/expansion/pipelines.rs:136
41: ion_shell::expansion::pipelines::Pipeline<ion_shell::shell::job::Job>::expand::{{closure}}
at ./src/lib/expansion/pipelines.rs:209
42: core::iter::adapters::map_try_fold::{{closure}}
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/adapters/mod.rs:912
43: core::iter::traits::iterator::Iterator::try_fold
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/traits/iterator.rs:1888
44: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::try_fold
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/adapters/mod.rs:938
45: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::try_fold
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/adapters/mod.rs:2949
46: core::iter::traits::iterator::Iterator::find
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/traits/iterator.rs:2231
47: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::next
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/adapters/mod.rs:2931
48: <alloc::vec::Vec<T> as alloc::vec::SpecFromIterNested<T,I>>::from_iter
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/alloc/src/vec.rs:2125
49: <alloc::vec::Vec<T> as alloc::vec::SpecFromIter<T,I>>::from_iter
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/alloc/src/vec.rs:2162
50: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/alloc/src/vec.rs:2002
51: core::iter::traits::iterator::Iterator::collect
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/traits/iterator.rs:1670
52: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter::{{closure}}
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/result.rs:1490
53: core::iter::adapters::process_results
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/adapters/mod.rs:2920
54: <core::result::Result<V,E> as core::iter::traits::collect::FromIterator<core::result::Result<A,E>>>::from_iter
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/result.rs:1490
55: core::iter::traits::iterator::Iterator::collect
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/iter/traits/iterator.rs:1670
56: ion_shell::expansion::pipelines::Pipeline<ion_shell::shell::job::Job>::expand
at ./src/lib/expansion/pipelines.rs:209
57: ion_shell::shell::Shell::run_pipeline
at ./src/lib/shell/mod.rs:301
58: ion_shell::shell::flow::<impl ion_shell::shell::Shell>::execute_statement
at ./src/lib/shell/flow.rs:387
59: ion_shell::shell::flow::<impl ion_shell::shell::Shell>::on_command
at ./src/lib/shell/flow.rs:577
60: ion::binary::InteractiveShell::exec_single_command
at ./src/binary/mod.rs:290
61: ion::binary::InteractiveShell::exec
at ./src/binary/mod.rs:343
62: ion::binary::InteractiveShell::execute_interactive
at ./src/binary/mod.rs:240
63: ion::main
at ./src/main.rs:271
64: core::ops::function::FnOnce::call_once
at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/ops/function.rs:227
kernel: linux5.10
version: ion 1.0.0-alpha (x86_64-unknown-linux-gnu)
/ rev 1f6b6224915713ddbf30c4405d7ce944f56ef7b4
compiled with DEBUG=1 RUSTUP=0 make
interaction: Alacritty with ion (alacritty -e ion
)
context: seems to happen simply if a decimal exists in the expression (ex: $(( . ))
will fail in ion, whereas in zsh, it will simply say zsh: bad floating point constant
)
behavior of bash/dash/zsh/fish/oil zsh:
$ echo $(( 3 / 4 ))
0
$ echo $(( 1 / 2 ))
0
$ echo $(( . ))
zsh: bad floating point constant