From 0e2eef3d2abe3f3c81f39b3ced52f9ce92d46c7e Mon Sep 17 00:00:00 2001 From: Vladimir Sedach Date: Tue, 13 Sep 2011 13:56:35 -0400 Subject: [PATCH] Fixed bug with function arguments not being respected for renaming by LET. Thanks to Scott Bell for the bug report. --- src/compiler.lisp | 1 + src/function-definition.lisp | 1 + src/special-operators.lisp | 1 + t/eval-tests.lisp | 6 ++++++ t/output-tests.lisp | 11 +++++++++++ 5 files changed, 20 insertions(+) diff --git a/src/compiler.lisp b/src/compiler.lisp index f06e828..ee382f7 100644 --- a/src/compiler.lisp +++ b/src/compiler.lisp @@ -77,6 +77,7 @@ lexical block.") (defvar *local-function-names* ()) ;; is a subset of (defvar *enclosing-lexicals* ()) +(defvar *enclosing-function-arguments* ()) (defvar *function-block-names* ()) (defvar *lexical-extent-return-tags* ()) (defvar *dynamic-extent-return-tags* ()) diff --git a/src/function-definition.lisp b/src/function-definition.lisp index 0a8fb7b..b22e245 100644 --- a/src/function-definition.lisp +++ b/src/function-definition.lisp @@ -113,6 +113,7 @@ Syntax of key spec: (defun compile-function-body (args body) (with-declaration-effects (body body) (let* ((*enclosing-lexical-block-declarations* ()) + (*enclosing-function-arguments* (append args *enclosing-function-arguments*)) (*enclosing-lexicals* (set-difference *enclosing-lexicals* args)) (body (let ((in-loop-scope? nil) (*loop-scope-lexicals* ()) diff --git a/src/special-operators.lisp b/src/special-operators.lisp index b231f1e..8838c69 100644 --- a/src/special-operators.lisp +++ b/src/special-operators.lisp @@ -348,6 +348,7 @@ normalized-bindings))) (flet ((maybe-rename-lexical-var (x) (if (or (member x *enclosing-lexicals*) + (member x *enclosing-function-arguments*) (lookup-macro-def x *symbol-macro-env*) (member x free-variables-in-binding-value-expressions)) (ps-gensym (string x)) diff --git a/t/eval-tests.lisp b/t/eval-tests.lisp index e5963b8..5de1df9 100644 --- a/t/eval-tests.lisp +++ b/t/eval-tests.lisp @@ -31,3 +31,9 @@ (array) (js-array (make-array 0 :adjustable t))) +(test-js-eval funargs-let1 + ((lambda (x) + (let ((x 10)) + (incf x)) + (incf x)) 0) + 1) diff --git a/t/output-tests.lisp b/t/output-tests.lisp index e3fc0f4..a91834e 100644 --- a/t/output-tests.lisp +++ b/t/output-tests.lisp @@ -2862,3 +2862,14 @@ function (x) { (test-ps-js divide-expressions1 (floor (1- x) y) "Math.floor((x - 1) / y);") + +(test-ps-js lexical-funargs-shadow1 + (lambda (x) + (let ((x 1)) + (foo x)) + (incf x)) + "function (x) { + var x1 = 1; + foo(x1); + return ++x; +};") -- 2.11.4.GIT