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

strangeness when macro is closure for proc #3855

Open
shaunc opened this issue Feb 11, 2016 · 5 comments
Open

strangeness when macro is closure for proc #3855

shaunc opened this issue Feb 11, 2016 · 5 comments
Labels
VM see also `const` label

Comments

@shaunc
Copy link

shaunc commented Feb 11, 2016

The following code:

macro foo(a : static[string]) : typed =
  proc bar() : void =
    discard capitalize(a)
  bar()
discard foo("foo")

Generates:

parameter.nim(139, 12) template/generic instantiation from here 
lib/pure/strutils.nim(242, 21) Error: attempt to access a nil address
@Araq Araq added the VM see also `const` label label Apr 4, 2016
@Araq
Copy link
Member

Araq commented Feb 5, 2017

I think lambda-lifting doesn't consider macro properly.

@metagn
Copy link
Collaborator

metagn commented Apr 25, 2020

Does not error anymore, with 1.2.0 My mistake, with 1.2.0, if you replace discard capitalize with echo capitalizeAscii it prints an empty line, so the string is still zeroed in memory

@ringabout
Copy link
Member

Updated example:

import strutils

macro foo(a : static[string]) =
  proc bar() =
    echo capitalizeAscii(a)
  bar()

foo("foo")

@metagn
Copy link
Collaborator

metagn commented Nov 12, 2020

Even simpler:

macro foo(a: static[string]) =
  proc bar() =
    echo a
  bar()

foo("foo")

@demotomohiro
Copy link
Contributor

I found similar strange bug with static[int] type.

macro foo(a: static[int]) =
  echo a
  proc bar() =
    echo a
  bar()

foo(123)

Output:

0
0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VM see also `const` label
Projects
None yet
Development

No branches or pull requests

5 participants