bakpakin / Fennel

Lua Lisp Language
https://fennel-lang.org
MIT License
2.44k stars 126 forks source link

Cannot rename argument when using docstring and metadata at the same time in lambda #474

Closed m15a closed 8 months ago

m15a commented 8 months ago

Hi! I'm currently trying to write functions annotated by both docstring and metadata. I've noticed that renaming non-varg arguments using metadata :fnl/arglist in lambda fails. It's fine in fn on the other hand.

Versions

Minimal examples:

Metadata only cases. No problem.

;; metadata-only.fnl

(macro p [...]
  (do (print ...)
      '(do :nothing)))

(fn fn-without-arglist-renamed [x]
  {:fnl/docstring "docstring"
   :fnl/arglist [x]}
  (do :something))
(p "OK: fn without arglist renamed")

(fn fn-with-arglist-renamed [x]
  {:fnl/docstring "docstring"
   :fnl/arglist [y]}
  (do :something))
(p "OK: fn with arglist renamed")

(lambda lambda-without-arglist-renamed [x]
  {:fnl/docstring "docstring"
   :fnl/arglist [x]}
  (do :something))
(p "OK: lambda without arglist renamed")

(lambda lambda-with-arglist-renamed [x]
  {:fnl/docstring "docstring"
   :fnl/arglist [y]}
  (do :something))
(p "OK: lambda with arglist renamed")
$ fennel metadata-only.fnl
OK: fn without arglist renamed
OK: fn with arglist renamed
OK: lambda without arglist renamed
OK: lambda with arglist renamed

Mixture of both. Compile error.

;; docstring-and-metadata.fnl

(macro p [...]
  (do (print ...)
      '(do :nothing)))

(fn fn-without-arglist-renamed [x]
  "docstring"
  {:fnl/arglist [x]}
  (do :something))
(p "OK: fn without arglist renamed")

(fn fn-with-arglist-renamed [x]
  "docstring"
  {:fnl/arglist [y]}
  (do :something))
(p "OK: fn with arglist renamed")

(lambda lambda-without-arglist-renamed [x]
  "docstring"
  {:fnl/arglist [x]}
  (do :something))
(p "OK: lambda without arglist renamed")

(lambda lambda-with-arglist-renamed [x]
  "docstring"
  {:fnl/arglist [y]}
  (do :something))
(p "OK: lambda with arglist renamed")
$ fennel docstring-and-metadata.fnl
OK: fn without arglist renamed
OK: fn with arglist renamed
OK: lambda without arglist renamed
docstring-and-metadata.fnl:27:17 Compile error: unknown identifier: y

  {:fnl/arglist [y]}
* Try looking to see if there's a typo.
* Try using the _G table instead, eg. _G.y if you really want a global.
* Try moving this code to somewhere that y is in scope.
* Try binding y as a local in the scope of this code.
technomancy commented 8 months ago

Thanks for catching this! I think I've got it fixed now.