nitely / nim-regex

Pure Nim regex engine. Guarantees linear time matching
https://nitely.github.io/nim-regex/
MIT License
225 stars 20 forks source link

compiling a regular expression from command line arguments crashes the Nim compiler #107

Closed Cloudperry closed 2 years ago

Cloudperry commented 2 years ago

Compiling the following program with Nim 1.4.8 crashes the compiler:

import os, regex
discard re(commandLineParams()[0])

Running the same program through nimsuggest also crashes the nimsuggest instance. The program compiles when regex is replaced with re or nre. I don't know yet if this is a compiler bug or a nim-regex bug, but it sure seems like its in nim-regex.

Cloudperry commented 2 years ago

This is the compiler output:

roni@roni-desktop ~/Testing> nim c nimRegexBug.nim
Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: used config file '/etc/nim/config.nims' [Conf]
..........................................Traceback from system (most recent call last)
Error: unhandled exception: index -1 not in 0 .. 0 [IndexDefect]

I don't see any useful information there, but at least it tells that the compiler crashes before c codegen happens. The crash happens on all backends except javascript and is unaffected by the choice of gc.

The workaround for this is to first store the command line argument to a variable. This compiles:

import os, regex

let firstArg = commandLineParams()[0]
discard re(firstArg)
Cloudperry commented 2 years ago

Clearly not a nim-regex bug. Idk why I thought it wasn't a compiler bug.