astrale-sharp / typstfmt

Apache License 2.0
253 stars 25 forks source link

Panic when formatting math eq. with alignments #137

Closed WannesMalfait closed 10 months ago

WannesMalfait commented 11 months ago

Bug description

When running typstfmt on:

$
  a
  &= b\
  &= c & d
$

the formatter panics:

thread 'main' panicked at library/alloc/src/raw_vec.rs:534:5:
capacity overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Extra info

astrale-sharp commented 11 months ago

wow, thanks for the bug report !

Needs urgent investigation cause that's a very reasonable snippet

astrale-sharp commented 11 months ago

(plus we should never panic)

astrale-sharp commented 11 months ago

running the debug version shows a debug assertion fails align point 4 is smaller than position 5

astrale-sharp commented 11 months ago

running in release I see the same panic you do

astrale-sharp commented 11 months ago

probably gonna interest you @taooceros

astrale-sharp commented 11 months ago

A fixing PR should add a new test containing the problem snippet if anyone else than me is interested

taooceros commented 11 months ago

Huh capacity overflow. That doesn't seem common. I can take a look later today.

teoc98 commented 11 months ago

A temporary solution that I found: start new lines more often e.g.

  $
    a &= b \
      &= c
      & d
  $

Maybe it can give some insights on why it fails