ruby-changes:64151
From: Nobuyoshi <ko1@a...>
Date: Mon, 14 Dec 2020 19:29:52 +0900 (JST)
Subject: [ruby-changes:64151] 7060aeedbd (master): shareable_constant_value: is effective only in comment-only line
https://git.ruby-lang.org/ruby.git/commit/?id=7060aeedbd From 7060aeedbd69c0888379cbf91f0bb2208bc59308 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 2 Nov 2020 19:48:17 +0900 Subject: shareable_constant_value: is effective only in comment-only line diff --git a/parse.y b/parse.y index 84a6efd..fa2139b 100644 --- a/parse.y +++ b/parse.y @@ -7999,6 +7999,13 @@ parser_set_compile_option_flag(struct parser_params *p, const char *name, const https://github.com/ruby/ruby/blob/trunk/parse.y#L7999 static void 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); if (b >= 0) p->ctxt.shareable_constant_value = b; } diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 4b6f422..8a644ad 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -1178,26 +1178,27 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L1178 assert_warning(/invalid value/) do assert_valid_syntax("# shareable_constant_value: invalid-option", verbose: true) 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;'}") begin; # shareable_constant_value: true A = [[1]] # shareable_constant_value: false B = [[2]] - C = # shareable_constant_value: true - [[3]] - [A, B, C] + [A, B] end; assert_send([Ractor, :shareable?, a]) assert_not_send([Ractor, :shareable?, b]) - assert_send([Ractor, :shareable?, c]) assert_equal([1], a[0]) assert_send([Ractor, :shareable?, a[0]]) a, b = Class.new.class_eval("#{<<~"begin;"}\n#{<<~'end;'}") begin; # shareable_constant_value: false - class X # shareable_constant_value: true + class X + # shareable_constant_value: true A = [[1]] end B = [] -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/