Skip to content

Commit

Permalink
[PRISM] Correctly parse non-base 10 integers in Prism
Browse files Browse the repository at this point in the history
This commit passes an `end` to rb_int_parse_cstr which allows us
to correctly parse non-base 10 integers which are enclosed in
parenthesis. Prior to this commit, we were getting a putobject nil
when compiling `(0o0)` for example.
  • Loading branch information
jemmaissroff committed Dec 13, 2023
1 parent a2994c3 commit 196c246
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions prism_compile.c
Expand Up @@ -78,8 +78,8 @@ pm_iseq_new_with_opt(pm_scope_node_t *scope_node, pm_parser_t *parser, VALUE nam
static VALUE
parse_integer(const pm_integer_node_t *node)
{
const char *start = (const char *) node->base.location.start;
const char *end = (const char *) node->base.location.end;
char *start = (char *) node->base.location.start;
char *end = (char *) node->base.location.end;

size_t length = end - start;
int base = -10;
Expand All @@ -101,7 +101,7 @@ parse_integer(const pm_integer_node_t *node)
rb_bug("Unexpected integer base");
}

return rb_int_parse_cstr(start, length, NULL, NULL, base, RB_INT_PARSE_DEFAULT);
return rb_int_parse_cstr(start, length, &end, NULL, base, RB_INT_PARSE_DEFAULT);
}

static VALUE
Expand Down
1 change: 1 addition & 0 deletions test/ruby/test_compile_prism.rb
Expand Up @@ -34,6 +34,7 @@ def test_IntegerNode
assert_prism_eval("0b10")
assert_prism_eval("0o10")
assert_prism_eval("010")
assert_prism_eval("(0o00)")
end

def test_NilNode
Expand Down

0 comments on commit 196c246

Please sign in to comment.