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

Better error message for missing optional-groups access in Regex #3978

Closed
spalladino opened this issue Feb 2, 2017 · 2 comments
Closed

Better error message for missing optional-groups access in Regex #3978

spalladino opened this issue Feb 2, 2017 · 2 comments
Labels
good first issue This is an issue suited for newcomers to become aquianted with working on the codebase. kind:bug topic:stdlib

Comments

@spalladino
Copy link
Contributor

The following code fails with a Nil assertion failed:

/(A)?B/ =~ "B"
p $1

Full stack trace being:

Nil assertion failed (Exception)
0x10f4205a2: *CallStack::unwind:Array(Pointer(Void)) at ??
0x10f420541: *CallStack#initialize:Array(Pointer(Void)) at ??
0x10f420518: *CallStack::new:CallStack at ??
0x10f41c521: *raise<Exception>:NoReturn at ??
0x10f41c501: *raise<String>:NoReturn at ??
0x10f4331f3: *Nil#not_nil!:NoReturn at ??
0x10f44d34e: *Regex::MatchData#[]<Int32>:String at ??
0x10f41c0d0: __crystal_main at ??
0x10f41f958: main at ??

This happens because the first capturing group was optional, and not present in the current match, so when tried to be cast to String it fails. Note that using String? works.

However, the error message should be more descriptive (similar to the Missing hash key when accessing a hash) to avoid confusion. See #3971 for example.

@akzhan
Copy link
Contributor

akzhan commented Jun 12, 2017

I believe that this issue should be closed.

@asterite
Copy link
Member

Indeed, this seems to be fixed. @akzhan Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This is an issue suited for newcomers to become aquianted with working on the codebase. kind:bug topic:stdlib
Projects
None yet
Development

No branches or pull requests

3 participants