Hi,

Given two templates splitre() and splitnre() which are almost identical

import strutils, re, nre

proc makeDiscardable[T](a: T): T {.discardable.} = a

template splitre*(source: string, dest: untyped, match: string): int =
  
  when compiles(dest):
    dest = re.split(source, re.re("(?s)" & match, {}))
  else:
    var dest = re.split(source, re.re("(?s)" & match, {}))
  
  if dest[0] == source:  # no match
    delete(dest, 0)
    makeDiscardable(0)
  else:
    makeDiscardable(dest.len)

template splitnre*(source: string, dest: untyped, match: string): int =
  
  when compiles(dest):
    dest = nre.split(source, nre.re("(?s)" & match))
  else:
    var dest = nre.split(source, nre.re("(?s)" & match))
  
  if dest[0] == source:  # no match
    delete(dest, 0)
    makeDiscardable(0)
  else:
    makeDiscardable(dest.len)

echo $splitre( "the is is", arr, "is")
echo $splitnre("the is is", arr, "is")

They both work (the output is "2 2"), but splitre() generates a message at compile

template/generic instantiation from here

"Here" being the point of call of the template (ie. echo $splitre).

I can't figure out why one generates the message and not the other, since the only difference is re vs nre

2017-01-11 22:09:44
This hint should accompany some error message. But the example works well for me (no such message). 2017-01-12 18:41:00