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

Can't compile ((. "" a) b) #2625

Open
prendradjaja opened this issue Jan 7, 2025 · 1 comment · May be fixed by #2626
Open

Can't compile ((. "" a) b) #2625

prendradjaja opened this issue Jan 7, 2025 · 1 comment · May be fixed by #2626
Labels

Comments

@prendradjaja
Copy link

prendradjaja commented Jan 7, 2025

Hello! This project is awesome :)

This bug isn't causing a problem for me (and there are workarounds, see below), but sharing in case the report is helpful.

Hy version: Hy 1.0.0 (Afternoon Review) using CPython(main) 3.13.1 on Darwin (I tried it in the web console too, with the same result.)

Repro instructions

In the REPL:

=> (setv abc ["a" "b" "c"])
=> ((. "" join) abc)

Expected result: "abc"
Actual: Compile-time error (below)

Note: I'm not doing (. "" (join abc)), which is probably a more typical syntax. That version does work! (Evaluates to "abc" as I'd expect)

My intended meaning is (''.join)(abc) in Python. Pretty sure I got the syntax right -- I tried it with a non-empty string literal e.g. ((. "," join) abc) and that did work as I expected, evaluating to "a,b,c".)

Traceback (most recent call last):
  File "stdin-3d4361c4adda2e092f2deff083d8b83bf335d68f", line 1, in <module>
    ((. "" join) abc)
hy.errors.HyCompileError: Internal Compiler Bug
 Traceback (most recent call last):
  File "/usr/local/Cellar/hy/1.0.0/libexec/lib/python3.13/site-packages/hy/compiler.py", line 411, in compile
    ret = self.compile_atom(tree)
  File "/usr/local/Cellar/hy/1.0.0/libexec/lib/python3.13/site-packages/hy/compiler.py", line 405, in compile_atom
    return Result() + _model_compilers[type(atom)](self, atom)
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/local/Cellar/hy/1.0.0/libexec/lib/python3.13/site-packages/hy/compiler.py", line 566, in compile_expression
    expr = macroexpand(expr, self.module, self)
  File "/usr/local/Cellar/hy/1.0.0/libexec/lib/python3.13/site-packages/hy/macros.py", line 361, in macroexpand
    fn = ".".join(map(mangle, fn[1:]))
  File "/usr/local/Cellar/hy/1.0.0/libexec/lib/python3.13/site-packages/hy/reader/mangling.py", line 32, in mangle
    assert s
           ^
AssertionError

Workarounds

For my use case, this is a good workaround:

=> (setv abc ["a" "b" "c"])
=> (setv list-to-string (. "" join))
=> (list-to-string abc)
"abc"
@Kodiologist
Copy link
Member

Yep, this is a bug. Thanks. Typically I'd write ((. "" join) x) as (.join "" x), which also works.

@Kodiologist Kodiologist added the bug label Jan 7, 2025
@Kodiologist Kodiologist changed the title Bug: Empty string literal + join + "bound method"... Can't compile ((. "" a) b) Jan 7, 2025
@Kodiologist Kodiologist linked a pull request Jan 7, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants