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

Incorrect symbol binding inside a macro #7889

Closed
xomachine opened this issue May 27, 2018 · 2 comments · Fixed by #22564
Closed

Incorrect symbol binding inside a macro #7889

xomachine opened this issue May 27, 2018 · 2 comments · Fixed by #22564
Labels
Macros quote do stale Staled PR/issues; remove the label after fixing them works_but_needs_test_case

Comments

@xomachine
Copy link
Contributor

Lets consider the example:

# binder.nim
from streams import newStringStream, readData, writeData
from macros import quote

macro bindme*(): untyped =
  quote do:
    var tst = "sometext"
    var ss = newStringStream("anothertext")
    ss.writeData(tst[0].addr, 2)
    discard ss.readData(tst[0].addr, 2) # <= comment this out to make compilation successful
# test.nim
from binder import bindme

bindme()

Then try to compile it:

$ nim c test.nim
Hint: used config file '/home/xomachine/.Soft/projects/Nim/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: binder [Processing]
Hint: streams [Processing]
Hint: macros [Processing]
test.nim(5, 7) template/generic instantiation from here
binder.nim(9, 15) Error: attempting to call undeclared routine: 'readData'
Traceback (most recent call last)
nim.nim(121)             nim
nim.nim(77)              handleCmdLine
main.nim(173)            mainCommand
main.nim(77)             commandCompileToC
modules.nim(242)         compileProject
modules.nim(182)         compileModule
passes.nim(250)          processModule
passes.nim(139)          processTopLevelStmt
sem.nim(576)             myProcess
sem.nim(544)             semStmtAndGenerateGenerics
semstmts.nim(1929)       semStmt
semexprs.nim(797)        semExprNoType
semexprs.nim(2285)       semExpr
semexprs.nim(781)        semDirectOp
semexprs.nim(677)        afterCallActions
sem.nim(443)             semMacroExpr
sem.nim(395)             semAfterMacroCall
semexprs.nim(2398)       semExpr
semstmts.nim(1862)       semStmtList
semexprs.nim(2404)       semExpr
semstmts.nim(19)         semDiscard
semexprs.nim(44)         semExprWithType
semexprs.nim(2318)       semExpr
semexprs.nim(704)        semIndirectOp
semexprs.nim(2316)       semExpr
semexprs.nim(780)        semDirectOp
semexprs.nim(633)        semOverloadedCallAnalyseEffects
semcall.nim(428)         semOverloadedCall
semcall.nim(305)         resolveOverloads
msgs.nim(1052)           localError
msgs.nim(1037)           liMessage
msgs.nim(891)            handleError
msgs.nim(876)            quit

When the readData call highlighted inside the binder.nim is commented out, the compilation becomes successful. It is wondering because the writeData call from the same library works as intended.
Nim version:

$ nim -v
Nim Compiler Version 0.18.1 [Linux: amd64]
Compiled at 2018-05-27
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 7e8eadb6ba9c94ea429ee7178e8cc8fbcbf558ea
active boot switches:

git bisect shows that the problem has been introduced with this commit: bbb0fd4

Adding a dummy readData declaration like this:

readData*() = discard

to lib/pure/streams.nim fixes the compilation.

@stale
Copy link

stale bot commented Aug 4, 2020

This issue has been automatically marked as stale because it has not had recent activity. If you think it is still a valid issue, write a comment below; otherwise it will be closed. Thank you for your contributions.

@stale stale bot added the stale Staled PR/issues; remove the label after fixing them label Aug 4, 2020
@metagn
Copy link
Collaborator

metagn commented Aug 23, 2023

Now compiles after fully importing macros but segfaults at runtime, not sure if that's just a quirk of the test case

metagn added a commit to metagn/Nim that referenced this issue Aug 27, 2023
closes nim-lang#12582, closes nim-lang#19552, closes nim-lang#2465, closes nim-lang#4596, closes nim-lang#15246,
closes nim-lang#12683, closes nim-lang#7889, closes nim-lang#4547, closes nim-lang#12415, closes nim-lang#2002,
closes nim-lang#1771, closes nim-lang#5121

The test for nim-lang#5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.
@Araq Araq closed this as completed in c19fd69 Aug 27, 2023
narimiran pushed a commit that referenced this issue Sep 18, 2023
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test

(cherry picked from commit c19fd69)
narimiran pushed a commit that referenced this issue Sep 18, 2023
* test case haul for old generic/template/macro issues

closes #12582, closes #19552, closes #2465, closes #4596, closes #15246,
closes #12683, closes #7889, closes #4547, closes #12415, closes #2002,
closes #1771, closes #5121

The test for #5648 is also moved into its own test
from `types/tissues_types` due to not being joinable.

* fix template gensym test

(cherry picked from commit c19fd69)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Macros quote do stale Staled PR/issues; remove the label after fixing them works_but_needs_test_case
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants