Skip to content

Fix INCF on a THE variable

username-removed-397096 requested to merge ralt/ecl:fix-the-incf into develop

The following code:

(let ((foo 0))
  (incf (the fixnum foo) (bar)))

was being expanded into:

(let ((foo 0))
  (LET* ((#:G133 (BAR)) (#:G132 (THE FIXNUM (+ (THE FIXNUM FOO) (BAR)))))
    (DECLARE (:READ-ONLY #:G133))
    (SETQ FOO (THE FIXNUM #:G132))))

Which is obviously going to call (BAR) twice. If (BAR) has side-effects, then it is going to be buggy.

The old define-modify-macro had an issue with out-of-order INCF/DECF, which is why it was replaced with Bruno Haible's macro, which is supposed to improve THE handling. It turns out that the improvement is a bit broken, so we're just fixing this.

Fixes #401 (closed).

Edited by username-removed-397096

Merge request reports