greghendershott / racket-mode

Emacs major and minor modes for Racket: edit, REPL, check-syntax, debug, profile, packages, and more.
https://www.racket-mode.com/
GNU General Public License v3.0
682 stars 93 forks source link

"result arity mismatch" when using a contract with or/c and values #659

Closed lojic closed 1 year ago

lojic commented 1 year ago

I get the following error in the racket-mode REPL:

; result arity mismatch;
;  expected number of values not received
;   expected: 1
;   received: 2

When using a contract with or/c and values. Here is a small reproducible example:

#lang racket

(provide (contract-out
          [ foo
            (-> boolean? (or/c (values string? integer?)
                               (values #f #f))) ]))

(define (foo b)
  (if b
      (values "answer" 7)
      (values #f #f)))

An unsatisfactory workaround is to have values wrap the or/c instead of the or/c wrapping values, but that would allow, for example, (values string? #f) which is unacceptable.

The example compiles ok at the command line, but not in racket-mode.

Thanks!

Please copy all of the following lines and paste them into your bug report at https://github.com/greghendershott/racket-mode/issues/.

((alist-get 'racket-mode package-alist)
 #s(package-desc racket-mode
                 (20210727 1545)
                 "Racket editing, REPL, and more"
                 ((emacs
                   (25 1))
                  (faceup
                   (0 0 2))
                  (pos-tip
                   (20191127 1028)))
                 nil nil "/Users/badkins/.emacs.d/elpa/racket-mode-20210727.1545"
                 ((:url . "https://www.racket-mode.com/")
                  (:maintainer "Greg Hendershott")
                  (:authors
                   ("Greg Hendershott"))
                  (:commit . "ef9a3fed943495ec2b0c8258f8e00307d6434b17"))
                 nil))
((emacs-version "28.2")
 (system-type darwin)
 (x-gtk-use-system-tooltips UNDEFINED)
 (major-mode racket-repl-mode)
 (racket--el-source-dir "/Users/badkins/.emacs.d/elpa/racket-mode-20210727.1545/")
 (racket--rkt-source-dir "/Users/badkins/.emacs.d/elpa/racket-mode-20210727.1545/racket/")
 (racket-program "/Users/badkins/sync/github/racket/racket/bin/racket")
 (racket-command-timeout 10)
 (racket-path-from-emacs-to-racket-function identity)
 (racket-path-from-racket-to-emacs-function identity)
 (racket-browse-url-function racket-browse-url-using-temporary-file)
 (racket-documentation-search-location "https://docs.racket-lang.org/search/index.html?q=%s")
 (racket-xp-after-change-refresh-delay 1)
 (racket-xp-mode-lighter
  (:eval
   (racket--xp-mode-lighter)))
 (racket-xp-highlight-unused-regexp "^[^_]")
 (racket-repl-buffer-name-function nil)
 (racket-submodules-to-run
  ((test)
   (main)))
 (racket-memory-limit 2048)
 (racket-error-context medium)
 (racket-repl-history-directory "~/.emacs.d/racket-mode/")
 (racket-history-filter-regexp "\\`\\s *\\'")
 (racket-images-inline t)
 (racket-imagemagick-props nil)
 (racket-images-keep-last 100)
 (racket-images-system-viewer "open")
 (racket-pretty-print t)
 (racket-use-repl-submit-predicate nil)
 (racket-pretty-print t)
 (racket-indent-curly-as-sequence t)
 (racket-indent-sequence-depth 0)
 (racket-pretty-lambda nil)
 (racket-smart-open-bracket-enable nil)
 (racket-module-forms "\\s(\\(?:module[*+]?\\|library\\)")
 (racket-logger-config
  ((cm-accomplice . warning)
   (GC . info)
   (module-prefetch . warning)
   (optimizer . info)
   (racket/contract . error)
   (sequence-specialization . info)
   (* . fatal)))
 (racket-show-functions
  (racket-show-pseudo-tooltip)))
(enabled-minor-modes
 (abbrev-mode)
 (auto-composition-mode)
 (auto-compression-mode)
 (auto-encryption-mode)
 (auto-fill-mode)
 (auto-save-mode)
 (blink-cursor-mode)
 (column-number-mode)
 (csv-field-index-mode)
 (electric-indent-mode)
 (erc-autojoin-mode)
 (erc-button-mode)
 (erc-fill-mode)
 (erc-irccontrols-mode)
 (erc-list-mode)
 (erc-log-mode)
 (erc-match-mode)
 (erc-menu-mode)
 (erc-move-to-prompt-mode)
 (erc-netsplit-mode)
 (erc-networks-mode)
 (erc-noncommands-mode)
 (erc-pcomplete-mode)
 (erc-readonly-mode)
 (erc-ring-mode)
 (erc-stamp-mode)
 (erc-track-mode)
 (file-name-shadow-mode)
 (font-lock-mode)
 (global-eldoc-mode)
 (global-font-lock-mode)
 (line-number-mode)
 (menu-bar-mode)
 (mouse-wheel-mode)
 (semantic-minor-modes-format)
 (shell-dirtrack-mode)
 (show-paren-mode)
 (tooltip-mode)
 (transient-mark-mode))
(disabled-minor-modes
 (auto-fill-function)
 (auto-save-visited-mode)
 (buffer-face-mode)
 (buffer-read-only)
 (button-mode)
 (cl-old-struct-compat-mode)
 (compilation-minor-mode)
 (compilation-shell-minor-mode)
 (completion-in-region-mode)
 (context-menu-mode)
 (defining-kbd-macro)
 (desktop-save-mode)
 (diff-auto-refine-mode)
 (diff-minor-mode)
 (dired-hide-details-mode)
 (dired-isearch-filenames-mode)
 (dired-omit-mode)
 (eldoc-mode)
 (electric-layout-mode)
 (electric-quote-mode)
 (erc-keep-place-mode)
 (erc-scrolltobottom-mode)
 (erc-smiley-mode)
 (erc-track-minor-mode)
 (erc-unmorse-mode)
 (global-prettify-symbols-mode)
 (global-semantic-highlight-edits-mode)
 (global-semantic-highlight-func-mode)
 (global-semantic-show-parser-state-mode)
 (global-semantic-show-unmatched-syntax-mode)
 (global-semantic-stickyfunc-mode)
 (global-visual-line-mode)
 (global-whitespace-mode)
 (global-whitespace-newline-mode)
 (horizontal-scroll-bar-mode)
 (hs-minor-mode)
 (html-autoview-mode)
 (ido-everywhere)
 (indent-tabs-mode)
 (isearch-mode)
 (jit-lock-debug-mode)
 (lock-file-mode)
 (next-error-follow-minor-mode)
 (overwrite-mode)
 (paragraph-indent-minor-mode)
 (prettify-symbols-mode)
 (racket-smart-open-bracket-mode)
 (racket-xp-mode)
 (rectangle-mark-mode)
 (semantic-highlight-edits-mode)
 (semantic-highlight-func-mode)
 (semantic-mode)
 (semantic-show-parser-state-mode)
 (semantic-show-unmatched-syntax-mode)
 (semantic-stickyfunc-mode)
 (sgml-electric-tag-pair-mode)
 (sh-electric-here-document-mode)
 (size-indication-mode)
 (tab-bar-history-mode)
 (tab-bar-mode)
 (temp-buffer-resize-mode)
 (text-scale-mode)
 (timeclock-mode-line-display)
 (tool-bar-mode)
 (unify-8859-on-decoding-mode)
 (unify-8859-on-encoding-mode)
 (url-handler-mode)
 (use-hard-newlines)
 (vc-parent-buffer)
 (view-mode)
 (visible-mode)
 (visual-line-mode)
 (whitespace-mode)
 (whitespace-newline-mode)
 (window-divider-mode)
 (xref-etags-mode))
lojic commented 1 year ago

(sigh) it appears this is likely not a bug :( Although the example compiled ok, I received the same error at the command line that I did from racket-mode when I actually ran the app. I forgot that aspect of compiling in racket-mode vs. command line. I'll mark closed.

greghendershott commented 1 year ago

Although I might be misunderstanding, I think this is a run-time not compile-time error because or/c is a procedure, not syntax. And, at run-time, it's an error because a single procedure argument can't receive multiple values?

Having said all that if you gave me a pop-quiz I probably would have guessed wrongly that or/c is syntax not a procedure, and tried to write exactly what you reasonably wanted to write.

lojic commented 1 year ago

You are correct. I should've looked up or/c - I think I was just hoping the contract would magically work the way I wanted :) I think there is a way to get what I want with ->i, but in the end, I just went with the simpler (values (orc/c ...) (or/c ...)) as I have more pressing matters. Glad to know racket-mode is as solid as ever - I appreciate all you've done on it!