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
e7f5cd7d
Commit
e7f5cd7d
authored
Apr 21, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2097 from nobu/optional_arguments_in_rhs
fix optional arguments in rhs
parents
4654db4f
367118b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
src/parse.y
src/parse.y
+9
-3
test/t/syntax.rb
test/t/syntax.rb
+17
-0
No files found.
src/parse.y
View file @
e7f5cd7d
...
@@ -1075,7 +1075,7 @@ heredoc_end(parser_state *p)
...
@@ -1075,7 +1075,7 @@ heredoc_end(parser_state *p)
%type <nd> brace_block cmd_brace_block do_block lhs none f_bad_arg
%type <nd> brace_block cmd_brace_block do_block lhs none f_bad_arg
%type <nd> mlhs mlhs_list mlhs_post mlhs_basic mlhs_item mlhs_node mlhs_inner
%type <nd> mlhs mlhs_list mlhs_post mlhs_basic mlhs_item mlhs_node mlhs_inner
%type <id> fsym sym basic_symbol operation operation2 operation3
%type <id> fsym sym basic_symbol operation operation2 operation3
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg
f_opt_asgn
%type <nd> heredoc words symbols
%type <nd> heredoc words symbols
%token tUPLUS /* unary+ */
%token tUPLUS /* unary+ */
...
@@ -3052,10 +3052,16 @@ f_arg : f_arg_item
...
@@ -3052,10 +3052,16 @@ f_arg : f_arg_item
}
}
;
;
f_opt
: tIDENTIFIER '=' arg_value
f_opt
_asgn : tIDENTIFIER '='
{
{
local_add_f(p, $1);
local_add_f(p, $1);
$$ = cons(nsym($1), $3);
$$ = $1;
}
;
f_opt : f_opt_asgn arg_value
{
$$ = cons(nsym($1), $2);
}
}
;
;
...
...
test/t/syntax.rb
View file @
e7f5cd7d
...
@@ -272,3 +272,20 @@ assert('method definition in cmdarg') do
...
@@ -272,3 +272,20 @@ assert('method definition in cmdarg') do
end
end
true
true
end
end
assert
(
'optional argument in the rhs default expressions'
)
do
class
OptArgInRHS
def
foo
"method called"
end
def
t
(
foo
=
foo
)
foo
end
def
t2
(
foo
=
foo
())
foo
end
end
o
=
OptArgInRHS
.
new
assert_nil
(
o
.
t
)
assert_equal
(
"method called"
,
o
.
t2
)
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