Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re.match doesn't give error when matches.len is wrong #9472

Open
timotheecour opened this issue Oct 23, 2018 · 0 comments
Open

re.match doesn't give error when matches.len is wrong #9472

timotheecour opened this issue Oct 23, 2018 · 0 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Oct 23, 2018

returns true if s[start..] matches the pattern and the captured substrings in the array matches. If it does not match, nothing is written into matches and false is returned.

  • when passing var matches: seq[string] , I would expect re.match to resize matches instead of keeping it empty

Example

import std/re

proc test=
  block:
    var matches: array[2, string]
    if match("abcdefg", re"c(d)ef(g)", matches, 2):
      for s in matches:
        echo s       # => d g

  block:
    # BUG: should give CT (or at least RT) error
    var matches: array[1, string]
    if match("abcdefg", re"c(d)ef(g)", matches, 2):
      for s in matches:
        echo s

  block:
    # BUG: should give CT (or at least RT) error
    var matches: array[3, string]
    if match("abcdefg", re"c(d)ef(g)", matches, 2):
      for s in matches:
        echo s

  block:
    # BUG (or odd design decision): matches doesn't get populated and
    # stays empty; should instead resize accordingly
    var matches: seq[string]
    if match("abcdefg", re"c(d)ef(g)", matches, 2):
      for s in matches:
        echo s
    echo matches

test()

Current Output

d
g

d
g

@[]

Expected Output

CT error (if strings are known at compile time) or RT error

Honestly I'd rather we deprecate re in favor of nre instead of spending time fixing these issues (nre doesn't have that issue); but we should still document bugs until then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant