haltcase / glob

Pure Nim library for matching file paths against Unix style glob patterns.
https://glob.bolingen.me
MIT License
61 stars 5 forks source link

internal error: environment misses: dir #60

Closed sxq112358 closed 1 year ago

sxq112358 commented 1 year ago

Compile failed when use walkGlob or walkGlobKinds inside an iterator.

import os
import glob
proc test()=
    let it = iterator():string=
        for path in walkGlob("*","./"):
            yield path
test()

when compiling, it gives the following error: /home/***/.nimble/pkgs/glob-0.11.2/glob.nim(512, 33) Error: internal error: environment misses: dir

Nim Compiler Version 1.6.12 [Linux: amd64] on Archlinux and Nim Compiler Version 1.6.12 [Windows: amd64] on Windows11

haltcase commented 1 year ago

Looks like this is the source of the error, but I don't have any idea what the cause is. dir is defined on L506 and used shortly thereafter on L512:

https://github.com/haltcase/glob/blob/64f71af2fa4572c2bdf8987a56a427c1d88fc34f/src/glob.nim#L506-L512

Contributions/help investigating would be welcome for this one.

sxq112358 commented 1 year ago

Minimal reproducible example

from sequtils import toSeq

iterator test(dir:int):int=
  yield 1234

iterator walkGlobKinds (): int =
  let dir = 123
  let it = test(dir).toSeq()           #fail
  #let it3 = countup(0,dir,2).toSeq()  #fail

  #let it2 = collect:
  #  for i in test(dir):i  #pass

  #for i in test(dir):
  #  echo i                #pass

proc main()=
    let it = iterator():int=
        for path in walkGlobKinds():
            yield path
main()
sxq112358 commented 1 year ago

the compiler bug has been fixed. nim issue link