Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error raised when trying to ns-resolve a macro #720

Closed
ikappaki opened this issue Oct 15, 2023 · 0 comments
Closed

error raised when trying to ns-resolve a macro #720

ikappaki opened this issue Oct 15, 2023 · 0 comments

Comments

@ikappaki
Copy link
Contributor

basilisp throws and error when trying to ns-resolve a macro, e.g. if

ValueError: Namespace must be specified in Symbol if

to reproduce

  1. Open up a REPL
  2. try to ns-resolve 'if in the current ns, a ValueError is thrown
basilisp.user=> (ns-resolve *ns* 'if)
Traceback (most recent call last):
  File "C:\src\basilisp\src\basilisp\cli.py", line 306, in repl
    result = eval_str(lsrc, ctx, ns, eof)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\src\basilisp\src\basilisp\cli.py", line 52, in eval_str
    last = compiler.compile_and_exec_form(form, ctx, ns)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\src\basilisp\src\basilisp\lang\compiler\__init__.py", line 165, in compile_and_exec_form
    return getattr(ns.module, final_wrapped_name)()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REPL Input>", line 1, in __lisp_expr___67
  File "C:\src\basilisp\src\basilisp\lang\runtime.py", line 1872, in resolve_var
    return Var.find(resolve_alias(s, ns))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\src\basilisp\src\basilisp\lang\runtime.py", line 431, in find
    ns = Maybe(ns_qualified_sym.ns).or_else_raise(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\src\basilisp\src\basilisp\util.py", line 52, in or_else_raise
    raise raise_fn()
ValueError: Namespace must be specified in Symbol if

The expectation is to return nil.

In clojure

user=> (ns-resolve *ns* 'if)
nil
ikappaki added a commit to ikappaki/basilisp that referenced this issue Oct 15, 2023
ikappaki added a commit to ikappaki/basilisp that referenced this issue Dec 6, 2023
ikappaki added a commit to ikappaki/basilisp that referenced this issue Dec 14, 2023
ikappaki added a commit to ikappaki/basilisp that referenced this issue Dec 14, 2023
chrisrink10 added a commit that referenced this issue Dec 14, 2023
Hi,

could you please consider patch to fix an issue with with `ns-resolve`
erroring out on macros. It addresses #720.

(part of breaking the individual bugfixes from
#723)

Thanks

---------

Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
Co-authored-by: Chris Rink <chrisrink10@users.noreply.github.com>
chrisrink10 added a commit that referenced this issue Dec 28, 2023
Hi,

could you please review patch to port
[nbb](https://github.com/babashka/nbb)'s build in nrepl-server to
basilisp contrib. It addresses #412.

`nbb` has the same EPL-1.0 license as `basilisp` so I believe using its
code as the base for this PR should not cause licensing issues.

The nbb `bencode` module which is a dependency was ported as well.
Extensive tests were written for both.

The server has been tested to work with both
[CIDER](https://github.com/clojure-emacs/cider) and
[Calva](https://github.com/BetterThanTomorrow/calva) in VS-Code.

The server can be invoked with `baslisp nrepl-server`:
```
$ poetry run basilisp nrepl-server -h
usage: basilisp.cmd nrepl-server [-h] [--host HOST] [--port PORT] [--port-filepath PORT_FILEPATH]

Start the nREPL server.

optional arguments:
  -h, --help            show this help message and exit
  --host HOST           the interface address to bind to, defaults to 127.0.0.1.
  --port PORT           the port to connect to, defaults to 0 (random available port).
  --port-filepath PORT_FILEPATH
                        the file path where the server port number is output to, defaults to ".nrepl-port".
```

Several fixes were required to make it work, which are included as
separate commits in this PR prior to the main bencode and nrepl-server
commits. They address the following issues

- ~~Fixed issue with sort-* fns returning an error on empty seqs
(#716)~~
- Fix issue with `ns` being unavail after `in-ns` during `eval` (#718)
- Fixed issue with import modules aliasing using ns eval (#719)
- Fixed issue with `ns-resolve` throwing error on macros (#720)

support for the `basilisp.stacktrace/print-cause-trace` is also added
because it is requested by CIDER when an exception is thrown to show to
the user, which is essential, it partially addresses #721.

In addition, two issues were observed while running the tests in CI
- ~~The 1.6.0 was released few days ago and complains for an additional
type error in the generator, which is now ignored with this patch~~

``` 
Traceback (most recent call last):
#...
py311-mypy: commands[0]> mypy --config-file=C:\src\basilisp/pyproject.toml -p basilisp
src\basilisp\lang\compiler\generator.py:3530: error: Argument 1 to "fields" has incompatible type "type[IType]"; expected an attrs class  [misc]
src\basilisp\lang\compiler\generator.py:3530: note: Error code "misc" not covered by "type: ignore" comment
``` 

- The nrepl-server tests which are using threads were failing due to
trying to release an rlock which has been already released whose essence
is captured in #722, and is fixed with this patch as described in the
ticket by using `with self._lock.gen_rlock()` instead of a single
instance of `with self._rlock()`. The error was
```
    File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/basilisp/lang/runtime.py", line 706, in find
    return v
   File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/readerwriterlock/rwlock.py", line 49, in __exit__
    self.release()
   File "/home/runner/work/basilisp/basilisp/.tox/py39/lib/python3.9/site-packages/readerwriterlock/rwlock.py", line 344, in release
    if not self.v_locked: raise RELEASE_ERR_CLS(RELEASE_ERR_MSG)
 RuntimeError: release unlocked lock
```

I understand this could be a lot to go through and there likely to be
multiple iterations while I update the code with your feedback, of which
I'm looking forward to.

I have not written a nrepl-server section for the manual yet. I plan to
do this after a successful review, and will also update the changelog.

Thanks

---------

Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
Co-authored-by: Chris Rink <chrisrink10@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants