1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

shareable_constant_value: is effective only in comment-only line

This commit is contained in:
Nobuyoshi Nakada 2020-11-02 19:48:17 +09:00
parent 25cf1aca92
commit 7060aeedbd
Notes: git 2020-12-14 19:19:44 +09:00
2 changed files with 13 additions and 5 deletions

View file

@ -7999,6 +7999,13 @@ parser_set_compile_option_flag(struct parser_params *p, const char *name, const
static void static void
parser_set_shareable_constant_value(struct parser_params *p, const char *name, const char *val) parser_set_shareable_constant_value(struct parser_params *p, const char *name, const char *val)
{ {
for (const char *s = p->lex.pbeg, *e = p->lex.pcur; s < e; ++s) {
if (*s == ' ' || *s == '\t') continue;
if (*s == '#') break;
rb_warning1("`%s' is ignored unless in comment-only line", WARN_S(name));
return;
}
int b = parser_get_bool(p, name, val); int b = parser_get_bool(p, name, val);
if (b >= 0) p->ctxt.shareable_constant_value = b; if (b >= 0) p->ctxt.shareable_constant_value = b;
} }

View file

@ -1178,26 +1178,27 @@ x = __ENCODING__
assert_warning(/invalid value/) do assert_warning(/invalid value/) do
assert_valid_syntax("# shareable_constant_value: invalid-option", verbose: true) assert_valid_syntax("# shareable_constant_value: invalid-option", verbose: true)
end end
assert_warning(/ignored/) do
assert_valid_syntax("nil # shareable_constant_value: true", verbose: true)
end
a, b, c = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}") a, b, c = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}")
begin; begin;
# shareable_constant_value: true # shareable_constant_value: true
A = [[1]] A = [[1]]
# shareable_constant_value: false # shareable_constant_value: false
B = [[2]] B = [[2]]
C = # shareable_constant_value: true
[[3]]
[A, B, C] [A, B]
end; end;
assert_send([Ractor, :shareable?, a]) assert_send([Ractor, :shareable?, a])
assert_not_send([Ractor, :shareable?, b]) assert_not_send([Ractor, :shareable?, b])
assert_send([Ractor, :shareable?, c])
assert_equal([1], a[0]) assert_equal([1], a[0])
assert_send([Ractor, :shareable?, a[0]]) assert_send([Ractor, :shareable?, a[0]])
a, b = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}") a, b = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}")
begin; begin;
# shareable_constant_value: false # shareable_constant_value: false
class X # shareable_constant_value: true class X
# shareable_constant_value: true
A = [[1]] A = [[1]]
end end
B = [] B = []