Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
fee3c1c2
Unverified
Commit
fee3c1c2
authored
Dec 21, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Dec 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4889 from shuujii/_0-is-not-numbered-parameter
`_0` is not numbered parameter
parents
5cc595cb
74f564b0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
23 deletions
+20
-23
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+15
-22
test/t/syntax.rb
test/t/syntax.rb
+5
-1
No files found.
mrbgems/mruby-compiler/core/parse.y
View file @
fee3c1c2
...
...
@@ -74,8 +74,6 @@ typedef unsigned int stack_type;
#define NUM_SUFFIX_R (1<<0)
#define NUM_SUFFIX_I (1<<1)
#define NUMPARAM_MAX 9
static inline mrb_sym
intern_cstr_gen(parser_state *p, const char *s)
{
...
...
@@ -5954,6 +5952,8 @@ parser_yylex(parser_state *p)
case '_':
if (toklen(p) == 2 && ISDIGIT(tok(p)[1]) && p->nvars) {
int n = tok(p)[1] - '0';
if (n > 0) {
node *nvars = p->nvars->car;
while (nvars) {
...
...
@@ -5967,18 +5967,11 @@ parser_yylex(parser_state *p)
if (intn(p->nvars->cdr) < 0) {
yywarning(p, "numbered parameter in nested block");
}
if (n == 0) {
yyerror(p, "_0 is not available");
return 0;
}
if (n > NUMPARAM_MAX) {
yyerror(p, "too large numbered parameter");
return 0;
}
pylval.num = n;
p->lstate = EXPR_END;
return tNUMPARAM;
}
}
/* fall through */
default:
if (toklast(p) == '!' || toklast(p) == '?') {
...
...
test/t/syntax.rb
View file @
fee3c1c2
...
...
@@ -672,7 +672,6 @@ assert 'keyword arguments' do
assert_equal
([
:a
,
nil
,
:c
],
m
(
a: :a
,
c: :c
))
end
assert
(
'numbered parameters'
)
do
assert_equal
(
15
,
[
1
,
2
,
3
,
4
,
5
].
reduce
{
_1
+
_2
})
assert_equal
(
3
,
->
{
_1
+
_2
}.
call
(
1
,
2
))
...
...
@@ -680,3 +679,8 @@ assert('numbered parameters') do
assert_equal
(
5
,
->
a:
->
{
_1
}
{
a
}.
call
.
call
(
5
))
assert_equal
(
45
,
Proc
.
new
do
_1
+
_2
+
_3
+
_4
+
_5
+
_6
+
_7
+
_8
+
_9
end
.
call
(
*
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
]))
end
assert
(
'_0 is not numbered parameter'
)
do
_0
=
:l
assert_equal
(
:l
,
->
{
_0
}.
call
)
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment