Found couple of problems with the code below, not sure if it's a bug or I'm doing something wrong
1 That code would produce `SIGSEGV: Illegal storage access. (Attempt to read from nil?)` [play](https://play.nim-lang.org/#ix=2KuU) import strutils, sugar, nre proc my_replace*(s: string, r: Regex, by: string | (proc (match: string): string)): string = nre.replace(s, r, by) echo my_replace("abcde", re"[bcd]", (match) => match.to_upper) == "aBCDe" Run 2 This slight variation of the code won't compile [play](https://play.nim-lang.org/#ix=2KuV) import strutils, sugar, nre proc my_replace*(s: string, r: Regex, by: string | (proc (match: string): string)): string = nre.replace(s, r, by) echo my_replace("abcde", re"[bcd]", proc (match: string): string = match.to_upper) == "aBCDe" Run 3 But if you add one more function call - it will compile, but throws SIGSEV runtime error, [play](https://play.nim-lang.org/#ix=2KuX) import strutils, sugar, nre proc my_replace*(s: string, r: Regex, by: string | (proc (match: string): string)): string = nre.replace(s, r, by) echo my_replace("abcde", re"[bcd]", (match) => match.to_upper) == "aBCDe" echo my_replace("abcde", re"[bcd]", proc (match: string): string = match.to_upper) == "aBCDe" Run The problem would go avay if single proc with the union type `... by: string | (proc (match: string): string) ...` declared as 2 procs.