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: attempt to access a nil address kind: rkInt (caused by result[^1]) #16226

Closed
treeform opened this issue Dec 2, 2020 · 4 comments · Fixed by #15987
Closed

Error: attempt to access a nil address kind: rkInt (caused by result[^1]) #16226

treeform opened this issue Dec 2, 2020 · 4 comments · Fixed by #15987

Comments

@treeform
Copy link
Contributor

treeform commented Dec 2, 2020

New bug in devel: result[^1] breaks inside macros but result[len-1] work.

Example

import macros

proc bar(): string =
  result = "hi"
  echo result[^1]

macro foo() =
  echo bar()

foo()

Current Output

stack trace: (most recent call last)
C:\p\jsony\tests\foo.nim(8, 11) foo
C:\p\jsony\tests\foo.nim(5, 14) bar
C:\p\jsony\tests\foo.nim(10, 4) template/generic instantiation of `foo` from here
C:\p\jsony\tests\foo.nim(5, 14) Error: attempt to access a nil address kind: rkInt

Expected Output

during compile:

i
hi

Possible Solution

Worked on 1.4.0, breaks now.

This result[result.len-1] works though:

import macros

proc bar(): string =
  result = "hi"
  echo result[result.len-1]

macro foo() =
  echo bar()

foo()
nim c -v
Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2020-12-02
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release```
@metagn
Copy link
Collaborator

metagn commented Dec 2, 2020

#15461 causes this, might be solved by #15987

@treeform
Copy link
Contributor Author

treeform commented Dec 2, 2020

That's cool. I hope the fix will come out soon.

@timotheecour
Copy link
Member

I confirm that #15987 does fix this issue (and many others)

@treeform
Copy link
Contributor Author

treeform commented Dec 3, 2020

Great, thank you!

Araq pushed a commit that referenced this issue Dec 3, 2020
…s `addr(mystring[ind])` (index + index assignment) (#15987)

* fix #15939, fix #15464 VM now supports `addr(mystring[ind])` (index + index assignment), var char return etc
* cleanups
* cstring tests
* add test for bug #15464
* improve test coverage
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
nim-lang#16226 VM now supports `addr(mystring[ind])` (index + index assignment) (nim-lang#15987)

* fix nim-lang#15939, fix nim-lang#15464 VM now supports `addr(mystring[ind])` (index + index assignment), var char return etc
* cleanups
* cstring tests
* add test for bug nim-lang#15464
* improve test coverage
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
nim-lang#16226 VM now supports `addr(mystring[ind])` (index + index assignment) (nim-lang#15987)

* fix nim-lang#15939, fix nim-lang#15464 VM now supports `addr(mystring[ind])` (index + index assignment), var char return etc
* cleanups
* cstring tests
* add test for bug nim-lang#15464
* improve test coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants