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
e5799b5d
Unverified
Commit
e5799b5d
authored
Apr 25, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Apr 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4402 from shuujii/fix-modiying-class-variable-to-frozen-class
Fix modiying class variable to frozen class/module
parents
163a6d01
47206481
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletion
+28
-1
mrbgems/mruby-metaprog/test/metaprog.rb
mrbgems/mruby-metaprog/test/metaprog.rb
+7
-1
src/variable.c
src/variable.c
+2
-0
test/t/class.rb
test/t/class.rb
+19
-0
No files found.
mrbgems/mruby-metaprog/test/metaprog.rb
View file @
e5799b5d
...
...
@@ -171,7 +171,6 @@ assert('Module#class_variable_set', '15.2.2.4.18') do
@@foo
end
end
assert_equal
99
,
Test4ClassVariableSet
.
class_variable_set
(
:@@cv
,
99
)
assert_equal
101
,
Test4ClassVariableSet
.
class_variable_set
(
:@@foo
,
101
)
assert_true
Test4ClassVariableSet
.
class_variables
.
include?
:@@cv
...
...
@@ -180,6 +179,13 @@ assert('Module#class_variable_set', '15.2.2.4.18') do
%w[@@ @@1 @@x= @x @ x 1]
.
each
do
|
n
|
assert_raise
(
NameError
)
{
Test4ClassVariableSet
.
class_variable_set
(
n
,
1
)
}
end
m
=
Module
.
new
.
freeze
assert_raise
(
FrozenError
)
{
m
.
class_variable_set
(
:@@cv
,
1
)
}
parent
=
Class
.
new
{
class_variable_set
(
:@@a
,
nil
)
}.
freeze
child
=
Class
.
new
(
parent
)
assert_raise
(
FrozenError
)
{
child
.
class_variable_set
(
:@@a
,
1
)
}
end
assert
(
'Module#class_variables'
,
'15.2.2.4.19'
)
do
...
...
src/variable.c
View file @
e5799b5d
...
...
@@ -671,6 +671,7 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v)
iv_tbl
*
t
=
c
->
iv
;
if
(
iv_get
(
mrb
,
t
,
sym
,
NULL
))
{
mrb_check_frozen
(
mrb
,
c
);
iv_put
(
mrb
,
t
,
sym
,
v
);
mrb_write_barrier
(
mrb
,
(
struct
RBasic
*
)
c
);
return
;
...
...
@@ -698,6 +699,7 @@ mrb_mod_cv_set(mrb_state *mrb, struct RClass *c, mrb_sym sym, mrb_value v)
c
=
cls
;
}
mrb_check_frozen
(
mrb
,
c
);
if
(
!
c
->
iv
)
{
c
->
iv
=
iv_new
(
mrb
);
}
...
...
test/t/class.rb
View file @
e5799b5d
...
...
@@ -433,6 +433,25 @@ assert('overriding class variable with a module (#3235)') do
end
end
assert
(
'class variable for frozen class/module'
)
do
module
CVarForFrozenModule
freeze
assert_raise
(
FrozenError
)
{
@@cv
=
1
}
end
class
CVarForFrozenClassA
@@a
=
nil
freeze
end
class
CVarForFrozenClassB
<
CVarForFrozenClassA
def
a
=
(
v
)
@@a
=
v
end
end
b
=
CVarForFrozenClassB
.
new
assert_raise
(
FrozenError
)
{
b
.
a
=
1
}
end
assert
(
'class with non-class/module outer raises TypeError'
)
do
assert_raise
(
TypeError
)
{
class
0::C1
;
end
}
assert_raise
(
TypeError
)
{
class
[]
::
C2
;
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