Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index out of bounds stream error when compiling with C-c C-c on non-exhaustive match #1246

Open
macrologist opened this issue Sep 17, 2024 · 5 comments
Assignees

Comments

@macrologist
Copy link
Collaborator

macrologist commented Sep 17, 2024

(defpackage  #:ugg
     (:use #:coalton #:coalton-prelude))

(in-package #:ugg)

(named-readtables:in-readtable coalton:coalton)


(coalton-toplevel

  (define hmm
    (match (lisp Integer () (cl:random 3))
      (0 "hey")
      (2 "oh"))))

If you C-c C-c on the coalton-toplevel form, an index out of bounds for stream error is signalled

Index 110 out of bounds for stream #<CHAR-POSITION-STREAM {7008D3F3E3}>
[Condition of type COMMON-LISP:SIMPLE-ERROR]

This points to a possible bug in the reporting of warnings about match non-exhaustiveness.

If you C-c C-k this compiles fine.

@jbouwman jbouwman self-assigned this Sep 18, 2024
@jbouwman
Copy link
Collaborator

SWANK-COMPILE-STRING receives the 122 char string, and writes it to a temp file for compilation. If the coalton readtable isn't active, when the coalton-toplevel macro is expanded, the coalton readtable is bound, and the macro's body is printed, and provided as a string input stream, to a recursive invocation of cl:read.

The contents of that stream are:

(COALTON-TOPLEVEL
  (DEFINE HMM
    (MATCH (LISP INTEGER
               COMMON-LISP:NIL
             (COMMON-LISP:RANDOM 3))
      (0 "hey")
      (2 "oh"))))

So text positions in the two versions of the input no longer correspond.

@macrologist
Copy link
Collaborator Author

Ahh so the fact that I've only been seeing it with match is a red herring.

@jbouwman
Copy link
Collaborator

jbouwman commented Sep 19, 2024

I'll rewind main a bit to see how behavior has changed and add my findings here.

And moreover add your example to the test suite.

@jbouwman
Copy link
Collaborator

Ahh so the fact that I've only been seeing it with match is a red herring.

I also feel bound to mention that 'match' is a close homonym for an important type of herring https://en.wiktionary.org/wiki/Matjes

@jbouwman
Copy link
Collaborator

I'll rewind main a bit to see how behavior has changed and add my findings here.

For reference as of 34bc744 the non-exhaustive match is reported after C-c C-c as

; caught COMMON-LISP:STYLE-WARNING:
;   warn: Non-exhaustive match
;     --> /private/var/tmp/slimeMuww0B:4:4
;      |
;    4 |        (match (lisp Integer () (cl:random 3))
;      |  ______^
;      | | _____-
;    5 | ||       (0 "hey")
;    6 | ||       (2 "oh"))))
;      | ||_______________- Missing case _
;      | |________________^ non-exhaustive match
;   

; processing (COMMON-LISP:PROGN (COMMON-LISP:EVAL-WHEN # ...) ...)
; 
; compilation unit finished
;   caught 1 STYLE-WARNING condition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants