PaddiM8 / kalker

Scientific calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
https://kalker.xyz
MIT License
1.59k stars 70 forks source link

Panic when evaluating single quote #57

Closed 5225225 closed 2 years ago

5225225 commented 2 years ago

Just the input ' given to the web interpreter causes it to break.

Stack trace when using kalk 2.1.1 is

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:699:58
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/panicking.rs:103:14
   2: core::panicking::panic_bounds_check
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/panicking.rs:79:5
   3: <usize as core::slice::index::SliceIndex<[T]>>::index
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/slice/index.rs:184:10
   4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/slice/index.rs:15:9
   5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/alloc/src/vec/mod.rs:2464:9
   6: kalk::parser::split_into_variables
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:699:58
   7: kalk::parser::parse_identifier
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:693:9
   8: kalk::parser::parse_primary
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:544:34
   9: kalk::parser::parse_factorial
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:528:16
  10: kalk::parser::parse_exponent
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:516:16
  11: kalk::parser::parse_unary
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:507:16
  12: kalk::parser::parse_unit
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:487:16
  13: kalk::parser::parse_factor
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:444:20
  14: kalk::parser::parse_sum
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:430:20
  15: kalk::parser::parse_to
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:413:16
  16: kalk::parser::parse_equality
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:362:20
  17: kalk::parser::parse_expr
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:358:8
  18: kalk::parser::parse_stmt
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:202:38
  19: kalk::parser::parse
             at /home/jess/.cargo/registry/src/github.com-1ecc6299db9ec823/kalk-2.1.1/src/parser.rs:187:25
  20: scratch0RukYFR5I::main
             at ./main.rs:3:5
  21: core::ops::function::FnOnce::call_once
             at /rustc/9dd4ce80fb01d1ff5cb5002f08b7b3847b59e664/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
PaddiM8 commented 2 years ago

Fixed!