haskell / haskell-mode

Emacs mode for Haskell
http://haskell.github.io/haskell-mode/
GNU General Public License v3.0
1.33k stars 344 forks source link

Parse error for Haskell sections #1838

Open fredefox opened 9 months ago

fredefox commented 9 months ago

Consider the program:

main = print $ (`div` 2) 3

If you put the cursor inside the brackets anywhere except on the first back-tick character and hit C-M-u (backward-up-list) the cursor is placed at the beginning of the current buffer and a scan error is echoed to the *Messages* buffer:

up-list: Scan error: "Unbalanced parentheses", 1, 1

I tried to debug this, but I'm not great with lisp. I think it has to do with the fact that "plain" backward-sexp and haskell-backward-sexp don't agree on where to go when cursor is on the d in div. There is a comment in haskell-forward-sexp saying that:

Navigate backwards using plain `backward-sexp', assume that it skipped over at least one Haskell expression

If I switch to fundamental-mode I can see that this assumption doesn't hold if you call backward-sexp with the cursor on the d in div.

I would love to provide the patch, but I'm afraid I need help digging to locate the bug.

The bug is present in at least versions 20231115.1812 and 20240116.1718.

fredefox commented 1 month ago

FWIW haskell-ts-mode does not have this problem.