Commit b41b4add authored by Stefan Monnier's avatar Stefan Monnier

Fix spurious "Lexical argument shadows the dynamic variable" due to inlining

Before this patch doing:

    rm lisp/calendar/calendar.elc
    make lisp/calendar/cal-hebrew.elc

would spew out lots of spurious such warnings about a `date` argument,
pointing to code which has no `date` argument in sight.  This was
because that code had calls to inlinable functions (taking a `date`
argument) defined in `calendar.el`, and while `date` is a normal
lexical var at the site of those functions' definitions, it was
declared as dynbound at the call site.

* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand):
Don't impose our local context onto the inlined function.

* test/lisp/emacs-lisp/bytecomp-tests.el: Add matching test.
parent 931be5ee
Pipeline #8902 failed with stages
in 42 minutes and 26 seconds
......@@ -284,8 +284,10 @@
;; If `fn' is from the same file, it has already
;; been preprocessed!
`(function ,fn)
(byte-compile--reify-function fn)))))
;; Try and process it "in its original environment".
(let ((byte-compile-bound-variables nil))
(byte-compile--reify-function fn))))))
(if (eq (car-safe newfn) 'function)
(byte-compile-unfold-lambda `(,(cadr newfn) ,@(cdr form)))
;; This can happen because of macroexp-warn-and-return &co.
;; -*- lexical-binding: t; -*-
(defsubst foo-inlineable (foo-var)
(+ foo-var 2))
(provide 'foo-inlinable)
;; -*- lexical-binding: t; -*-
;; In this test, we try and make sure that inlined functions's code isn't
;; mistakenly re-interpreted in the caller's context: we import an
;; inlinable function from another file where `foo-var' is a normal
;; lexical variable, and then call(inline) it in a function where
;; `foo-var' is a dynamically-scoped variable.
(require 'foo-inlinable
(expand-file-name "foo-inlinable.el"
(or byte-compile-current-file load-file-name))))
(defvar foo-var)
(defun foo-fun ()
(+ (foo-inlineable 5) 1))
......@@ -713,6 +713,10 @@ Subtests signal errors if something goes wrong."
"defvar.*foo.*wider than.*characters")
"Lexical argument shadows" 'reverse)
;;;; Macro expansion.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment