GULPF / nimquery

Nim library for querying HTML using CSS-selectors (like JavaScripts document.querySelector)
MIT License
134 stars 8 forks source link

Error: 'exec' can have side effects #16

Closed eggplants closed 1 year ago

eggplants commented 2 years ago

I'm new to nim so I don't know much about this error, but shouldn't the exec func in nimquery be changed to proc?

$ nim c --app:lib --gc:arc --experimental:strictFuncs --out:fushin.so src/fushin.nim
Hint: used config file '/home/eggplants/.choosenim/toolchains/nim-1.6.6/config/nim.cfg' [Conf]
Hint: used config file '/home/eggplants/.choosenim/toolchains/nim-1.6.6/config/config.nims' [Conf]
Hint: used config file '/home/eggplants/prog/fushin/nim.cfg' [Conf]
.....................................................................................................
/home/eggplants/.nimble/pkgs/nimquery-2.0.0/nimquery.nim(757, 6) Error: 'exec' can have side effects
> /home/eggplants/.nimble/pkgs/nimquery-2.0.0/nimquery.nim(765, 43) Hint: 'exec' calls `.sideEffect` 'newXmlTree'
>> /home/eggplants/.choosenim/toolchains/nim-1.6.6/lib/pure/xmltree.nim(138, 6) Hint: 'newXmlTree' called by 'exec'
GULPF commented 2 years ago

Looks like a bug or limitation with strictFuncs to me. This is the stdlib code in newXmlTree the compiler complains about:

for i in 0..children.len-1: result.s[i] = children[i]

And here is a minimal reproduction of the compiler behavior:

type
  Node = ref object

# Accepted by the compiler
func ok(children: seq[Node]): seq[Node] =
    for i, c in children:
        result[i] = c

# Not accepted - compiler complains about side effects that doesn't exist
func notok(children: seq[Node]): seq[Node] =
    for i in 0..children.len-1:
        result[i] = children[i]