haskell-indentation: identifier named `signature` breaks indentation for the rest of the declaration

Abierto
#1,895 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@PerryLink ya está trabajando en esto.

Desde el 18/10/2026.

  • #1897 de @PerryLink — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
emacs-lisp, haskell

Línea de trabajo

Start with haskell-indentation-peek-token and its callers, especially haskell-indentation-find-indentations, then inspect the haskell-indentation-module entry for how Backpack signatures are handled. Also review the keyword list in haskell-font-lock.el. Done means ordinary signature identifiers no longer break indentation or receive keyword highlighting in .hs files, while .hsig support remains intact.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Description

haskell-indentation-mode treats signature as a keyword everywhere, not only in Backpack signature files (.hsig). Any ordinary identifier named signature (a record field, a variable, a binding) aborts the indentation parse: haskell-indentation-find-indentations returns nil, and every line after it in the same top-level declaration gets no indentation candidates.

signature is a common field/variable name in code dealing with cryptography or e-signing, so this is easy to hit in a regular .hs file.

Minimal reproduction

In a .hs buffer with haskell-indentation-mode:

f = R
  { a = 1
  , signature = 2
  }

With point at the end of the last line, (haskell-indentation-find-indentations) returns nil, so RET/TAB on the next line doesn't indent.

Renaming the field to sig gives (0 2) as expected. The same happens for a variable:

f signature = do
  g signature

→ nil (with sigx instead: (0 2 4)).

Cause

haskell-indentation-peek-token lexes signature as a keyword unconditionally:

(cond ((looking-at "\\(if\\|then\\|else\\|let\\|in\\|mdo\\|rec\\|do\\|proc\\|case\\|of\\|where\\|module\\|signature\\|deriving\\|import\\|data\\|type\\|newtype\\|class\\|instance\\)\\([^[:alnum:]'_]\\|$\\)")
       (match-string-no-properties 1))

signature was presumably added alongside the ("signature" . haskell-indentation-module) entry in haskell-indentation-toplevel-list to support Backpack. But signature is only a keyword at the start of an .hsig file. Everywhere else it's an ordinary identifier, and it isn't reserved in Haskell 2010 or GHC.

Suggested fix

Only lex signature as a keyword in .hsig files, or only where a module header could appear. The workaround I'm using (advice on haskell-indentation-peek-token) does the former:

(defun haskell-indentation-signature-as-identifier (peek-token)
  (if (and (looking-at "signature\\([^[:alnum:]'_]\\|$\\)")
           (not (string-suffix-p ".hsig" (or buffer-file-name ""))))
      'value
    (funcall peek-token)))

(advice-add 'haskell-indentation-peek-token
            :around #'haskell-indentation-signature-as-identifier)

With this, the examples above indent correctly, and so does a real-world module with previously broken indentation.

Related

haskell-font-lock.el also lists "signature" among the keywords, so signature identifiers are highlighted as keywords in .hs files. That's cosmetic, but it has the same root cause.

Environment
  • haskell-mode 20260206.1050 (MELPA)
  • GNU Emacs 30.2
Lenguaje dominante
Emacs Lisp
Estrellas
1.4k
Forks
357
Merge medio
7 h 50 min
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de haskell/haskell-mode

Todos los issues de haskell/haskell-mode

Issues similares

Más issues de DevTools

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.