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

internal error in genRdVar in vmgen.nim #14645

Open
jibal opened this issue Jun 12, 2020 · 8 comments
Open

internal error in genRdVar in vmgen.nim #14645

jibal opened this issue Jun 12, 2020 · 8 comments
Labels
Static[T] VM see also `const` label

Comments

@jibal
Copy link

jibal commented Jun 12, 2020

nim 1.2 on Windows

This code

import regex, strformat

proc p =
  for i in 1..1:
    const rx = re(&"")

produces this error message:

Error: internal error: (filename: "vmgen.nim", line: 1642, column: 22)

Note that this is the regex module from nimble ... it compiles regular expressions at compile time.

In reducing my actual code to a minimal failing case, I found that the iterator and the content of the string don't matter, but const, the calls to re and & (or fmt), as well as being inside a proc, are all necessary to produce the failure.

@nitely
Copy link
Contributor

nitely commented Jun 12, 2020

It seems related to static[T]. Here's a reduced case:

import strformat
proc re(s: static string): string = s
proc p =
  const rx = re(&"")

@ghost ghost added the VM see also `const` label label Jul 26, 2020
@ghost
Copy link

ghost commented Oct 22, 2020

I think it might not be related to static:

proc p =
  const rx = block:
    var fmtRes_14356029 = "" 
    fmtRes_14356029

fails as well

@ghost
Copy link

ghost commented Oct 22, 2020

Is this a duplicate of #12172 ?

@timotheecour
Copy link
Member

timotheecour commented Oct 23, 2020

probably not because top example produces
Error: internal error: /Users/timothee/git_clone/nim/Nim_prs/compiler/vmgen.nim(1632, 23)

whereas #12172 gives a different error

note: top example a bit reduced (without iterator):

import regex, strformat
proc p =
  const rx = re(&"")

@timotheecour timotheecour changed the title assertion failure in genRdVar in vmgen.nim internal error in genRdVar in vmgen.nim Oct 23, 2020
@jibal
Copy link
Author

jibal commented Oct 24, 2020

I think it might not be related to static

AFAICS, your example has nothing to do with this defect, which is about a specific error message (a failure at a specific line in the compiler).

@jibal
Copy link
Author

jibal commented Oct 24, 2020

top example a bit reduced (without iterator):

nitely previously posted a reduced case without the iterator and without importing regex:

import strformat
proc re(s: static string): string = s
proc p =
  const rx = re(&"")

@nitely
Copy link
Contributor

nitely commented Oct 24, 2020

@jibal btw, here is a workaround:

import strformat
import regex
proc reCt(s: string): Regex {.compileTime.} = re(s)
proc p =
  const rx = reCt(&"")

@timotheecour
Copy link
Member

timotheecour commented Oct 24, 2020

here's the most straightforward way to circumvent this bug:

when true: # gitissue
  import strformat
  proc re(s: static string): string = s
  proc p =
    # const rx = re(&"") # BUG
    const rx = re(static(&"")) # ok

that might help for PR that would fix this

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

No branches or pull requests

3 participants