Skip to content

Conversation

@chrisrink10
Copy link
Member

@chrisrink10 chrisrink10 commented Sep 18, 2024

Fixes #1045

Replacement for #1051

For people looking here for issues arising after this PR merges, you may need to clear any cached bytecode. The easiest way to do that would be to use --disable-ns-cache on your CLI for basilisp run or basilisp repl.

Comment on lines +2598 to +2601
if "." in module_alias:
raise ctx.AnalyzerException(
"Python module alias must not contain '.'", form=f
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never actually worked, but it was not covered before. Imports always generated pretty 1-1 Lisp to Python code, so this naturally generated exactly the code that it appeared to generate. Unfortunately, the top-level alias name was never defined so Python would error out:

basilisp.user=> (import [re :as reg.ex])
<module 're' from '/Users/christopher/.pyenv/versions/3.12.1/lib/python3.12/re/__init__.py'>

basilisp.user=> (reg.ex/fullmatch #"[A-Z]+" "YES")
Traceback (most recent call last):
  File "/Users/christopher/Projects/basilisp/src/basilisp/cli.py", line 577, in repl
    result = eval_str(lsrc, ctx, ns, eof)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/christopher/Projects/basilisp/src/basilisp/cli.py", line 53, in eval_str
    last = compiler.compile_and_exec_form(form, ctx, ns)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/christopher/Projects/basilisp/src/basilisp/lang/compiler/__init__.py", line 194, in compile_and_exec_form
    return getattr(ns.module, final_wrapped_name)()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<REPL Input>", line 1, in __lisp_expr___6612
NameError: name 'reg' is not defined```

@chrisrink10 chrisrink10 marked this pull request as ready for review September 18, 2024 17:59
@chrisrink10 chrisrink10 merged commit 5511adf into main Sep 18, 2024
12 checks passed
@chrisrink10 chrisrink10 deleted the fix/namespace-aliasing-behavior-3 branch September 18, 2024 18:13
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

Successfully merging this pull request may close these issues.

Unclear behavior on alias shadowing

1 participant