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: internal error: genLiteral: ty is nil` when a `var` is accessed in `quote do` #9864

Closed
timotheecour opened this issue Dec 5, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@timotheecour
Copy link
Contributor

commented Dec 5, 2018

/cc @Araq
here's a minimal test case after a really painful reduction from cligen /cc @c-blake

import macros, tables

proc bar(shOpt: Table[string, int])=discard

macro dispatchGen(): untyped =
  var shOpt = initTable[string, int]()
  shOpt["foo"] = 10
  result = quote do:
     bar(`shOpt`)

dispatchGen()

nim c -r $timn_D/bugs/all/t0027.nim

/Users/timothee/git_clone/nim/timn/bugs/all/t0027.nim(15, 12) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/bugs/all/t0027.nim(15, 12) template/generic instantiation from here
???(0, 0) Error: internal error: genLiteral: ty is nil

note:

/cc @krux02

  • could be related to #9607 but probably not a dup, since the code presented here should be valid (and the fix suggested here #9607 (comment) doesn't apply here)
    also, since I found these other bugs while trying to debug this, the following could be related too:
  • maybe related to #9866
  • maybe related to #9865
@timotheecour

This comment has been minimized.

Copy link
Contributor Author

commented Dec 5, 2018

either related or a reduction:

#[
KEY 
D20181204T222045

/Users/timothee/git_clone/nim/timn/bugs/all/t0029.nim(28, 12) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/bugs/all/t0029.nim(28, 12) template/generic instantiation from here
/Users/timothee/git_clone/nim/timn/bugs/all/t0029.nim(23, 13) Error: internal error: genLiteral: ty is nil
    shOpt.data.setLen 1 # fails
]#

import macros

type
  Foo = object
    data: seq[int]

proc bar(a: Foo)=discard

proc shOpt(): auto =
  var shOpt: Foo
  # shOpt.data.setLen 0 # works
  shOpt.data.setLen 1 # fails
  shOpt

macro dispatchGen(): untyped =
  # const shOpt = shOpt() # works
  var shOpt = shOpt() # fails

  result = quote do:
     bar(`shOpt`)

dispatchGen()

Note: replacing var by const doesn't work in my original use case (can't compute it at CT inside the macro), so I still don't have a valid workaround

@timotheecour timotheecour added internal error and removed Crash labels Dec 5, 2018

@timotheecour timotheecour changed the title Error: internal error: genLiteral: ty is nil `Error: internal error: genLiteral: ty is nil` when a `var` is accessed in `quote do` Dec 5, 2018

@Araq Araq closed this in af815c3 Dec 5, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Dec 15, 2018

fixes nim-lang#9864 [backport]
(cherry picked from commit af815c3)

@narimiran narimiran added Crash and removed Crash labels Feb 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.