Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007844OCamlemacs modepublic2018-08-31 15:232018-09-13 14:58
Reporterwilfred 
Assigned Togasche 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.08.0+dev 
Summary0007844: imenu crash when a comment contains 'in'
Descriptionimenu in Emacs crashes when a comment contains the word 'in'. This also affects tuareg-mode.
Steps To ReproduceCreate an ocaml buffer with the following contents:

?(**
 * in
 *)

And run M-x imenu.

Traceback produced:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  buffer-substring-no-properties(nil nil)
  (if string (substring string begin end) (buffer-substring-no-properties begin end))
  (let* ((data (match-data)) (begin (nth (* 2 num) data)) (end (nth (1+ (* 2 num)) data))) (if string (substring string begin end) (buffer-substring-no-properties begin end)))
  caml-match-string(5)
  (cons (caml-match-string 5) (point))
  (setq index (cons (caml-match-string 5) (point)))
  (while (caml-prev-index-position-function) (setq index (cons (caml-match-string 5) (point))) "Macro to display a progress message.\nRELPOS is the relative position to display.\nIf RELPOS is nil, then the relative position in the buffer\nis calculated.\nPREVPOS is the variable in which we store the last position displayed." (setq all-alist (cons index all-alist)) (cond ((looking-at "[ \011]*and") (setq and-alist (cons index and-alist))) ((looking-at "[ \011]*let") (setq value-alist (cons index (append and-alist value-alist))) (setq and-alist nil)) ((looking-at "[ \011]*type") (setq type-alist (cons index (append and-alist type-alist))) (setq and-alist nil)) ((looking-at "[ \011]*class") (setq class-alist (cons index (append and-alist class-alist))) (setq and-alist nil)) ((looking-at "[ \011]*val") (setq value-alist (cons index value-alist))) ((looking-at "[ \011]*\\(module\\|functor\\)") (setq module-alist (cons index module-alist))) ((looking-at "[ \011]*method") (setq method-alist (cons index method-alist)))))
  (let (value-alist type-alist class-alist method-alist module-alist and-alist all-alist menu-alist (prev-pos (point-max)) index) (goto-char prev-pos) "Macro to display a progress message.\nRELPOS is the relative position to display.\nIf RELPOS is nil, then the relative position in the buffer\nis calculated.\nPREVPOS is the variable in which we store the last position displayed." (while (caml-prev-index-position-function) (setq index (cons (caml-match-string 5) (point))) "Macro to display a progress message.\nRELPOS is the relative position to display.\nIf RELPOS is nil, then the relative position in the buffer\nis calculated.\nPREVPOS is the variable in which we store the last position displayed." (setq all-alist (cons index all-alist)) (cond ((looking-at "[ \011]*and") (setq and-alist (cons index and-alist))) ((looking-at "[ \011]*let") (setq value-alist (cons index (append and-alist value-alist))) (setq and-alist nil)) ((looking-at "[ \011]*type") (setq type-alist (cons index (append and-alist type-alist))) (setq and-alist nil)) ((looking-at "[ \011]*class") (setq class-alist (cons index (append and-alist class-alist))) (setq and-alist nil)) ((looking-at "[ \011]*val") (setq value-alist (cons index value-alist))) ((looking-at "[ \011]*\\(module\\|functor\\)") (setq module-alist (cons index module-alist))) ((looking-at "[ \011]*method") (setq method-alist (cons index method-alist))))) (mapc (function (lambda (pair) (if (symbol-value (cdr pair)) (setq menu-alist (cons (cons (car pair) (sort (symbol-value (cdr pair)) 'imenu--sort-by-name)) menu-alist))))) '(("Values" . value-alist) ("Types" . type-alist) ("Modules" . module-alist) ("Methods" . method-alist) ("Classes" . class-alist))) (if all-alist (setq menu-alist (cons (cons "Index" all-alist) menu-alist))) "Macro to display a progress message.\nRELPOS is the relative position to display.\nIf RELPOS is nil, then the relative position in the buffer\nis calculated.\nPREVPOS is the variable in which we store the last position displayed." menu-alist)
  tuareg-imenu-create-index()
  imenu--make-index-alist()
  imenu-choose-buffer-index()
  byte-code("\300 C\207" [imenu-choose-buffer-index] 1)
  call-interactively(imenu record nil)
  command-execute(imenu record)

Note that tuareg-imenu-create-index is an alias for caml-create-index-function.
TagsNo tags attached.
Attached Files

- Relationships
has duplicate 0007689resolvedgasche imenu broken when "in" appears in comment 

-  Notes
(0019347)
wyuenho (reporter)
2018-09-09 14:31

I just ran into this problem too. It's quite annoying.
(0019348)
gasche (administrator)
2018-09-09 17:16

Would one of you be willing to debug the issue and propose a fix to the elisp code?
(0019355)
wyuenho (reporter)
2018-09-10 21:26

Further debugging shows that it's not that there's an "in" in a comment that causes this issue, but that the search doesn't stop when the beginning of the buffer is reached. So the code the is looking at the last regular expression match while expecting data from the current match, in which there isn't any.
(0019356)
wilfred (reporter)
2018-09-11 19:14

I think the problem is this:

caml-create-index-function calls caml-prev-index-position-function, which is intended to search backwards until it finds the previous definition suitable for imenu.

However, because caml-in-comment-p incorrectly returns nil, we think we've found a match. The bad match data is just a side effect of caml-prev-index-position-function returning a number when it's inside the comment.
(0019357)
wilfred (reporter)
2018-09-11 19:44

I've opened https://github.com/ocaml/ocaml/pull/2040 [^]
(0019358)
wyuenho (reporter)
2018-09-12 01:18

Ah ha! I'll test it out and report back on Github.

BTW, This bug seems to be a duplicate of 0007689.
(0019364)
gasche (administrator)
2018-09-13 14:57

This should now be fixed by Wilfred's pull request -- to be part of 4.08.

- Issue History
Date Modified Username Field Change
2018-08-31 15:23 wilfred New Issue
2018-09-09 14:31 wyuenho Note Added: 0019347
2018-09-09 17:16 gasche Note Added: 0019348
2018-09-10 21:26 wyuenho Note Added: 0019355
2018-09-11 19:14 wilfred Note Added: 0019356
2018-09-11 19:44 wilfred Note Added: 0019357
2018-09-12 01:18 wyuenho Note Added: 0019358
2018-09-12 06:06 nojebar Relationship added has duplicate 0007689
2018-09-13 14:57 gasche Note Added: 0019364
2018-09-13 14:57 gasche Status new => resolved
2018-09-13 14:57 gasche Fixed in Version => 4.08.0+dev
2018-09-13 14:57 gasche Resolution open => fixed
2018-09-13 14:57 gasche Assigned To => gasche


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker