mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 15:06:10 +02:00
parent
e1e6b4972f
commit
eb8efa42f0
4 changed files with 17 additions and 1 deletions
|
@ -290,6 +290,7 @@ warnings:
|
|||
- KEYWORD_EOL
|
||||
- LITERAL_IN_CONDITION_DEFAULT
|
||||
- LITERAL_IN_CONDITION_VERBOSE
|
||||
- SHAREABLE_CONSTANT_VALUE_LINE
|
||||
- SHEBANG_CARRIAGE_RETURN
|
||||
- UNEXPECTED_CARRIAGE_RETURN
|
||||
- UNREACHABLE_STATEMENT
|
||||
|
|
|
@ -8394,7 +8394,12 @@ parser_lex_magic_comment(pm_parser_t *parser, bool semantic_token_seen) {
|
|||
// If we have hit a ractor pragma, attempt to lex that.
|
||||
uint32_t value_length = (uint32_t) (value_end - value_start);
|
||||
if (key_length == 24 && pm_strncasecmp(key_source, (const uint8_t *) "shareable_constant_value", 24) == 0) {
|
||||
if (value_length == 4 && pm_strncasecmp(value_start, (const uint8_t *) "none", 4) == 0) {
|
||||
const uint8_t *cursor = parser->current.start;
|
||||
while ((cursor > parser->start) && ((cursor[-1] == ' ') || (cursor[-1] == '\t'))) cursor--;
|
||||
|
||||
if (!((cursor == parser->start) || (cursor[-1] == '\n'))) {
|
||||
pm_parser_warn_token(parser, &parser->current, PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE);
|
||||
} else if (value_length == 4 && pm_strncasecmp(value_start, (const uint8_t *) "none", 4) == 0) {
|
||||
pm_parser_scope_shareable_constant_set(parser, PM_SCOPE_SHAREABLE_CONSTANT_NONE);
|
||||
} else if (value_length == 7 && pm_strncasecmp(value_start, (const uint8_t *) "literal", 7) == 0) {
|
||||
pm_parser_scope_shareable_constant_set(parser, PM_SCOPE_SHAREABLE_CONSTANT_LITERAL);
|
||||
|
|
|
@ -373,6 +373,7 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
|
|||
[PM_WARN_KEYWORD_EOL] = { "`%.*s` at the end of line without an expression", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_LITERAL_IN_CONDITION_DEFAULT] = { "%sliteral in %s", PM_WARNING_LEVEL_DEFAULT },
|
||||
[PM_WARN_LITERAL_IN_CONDITION_VERBOSE] = { "%sliteral in %s", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_SHAREABLE_CONSTANT_VALUE_LINE] = { "'shareable_constant_value' is ignored unless in comment-only line", PM_WARNING_LEVEL_VERBOSE },
|
||||
[PM_WARN_SHEBANG_CARRIAGE_RETURN] = { "shebang line ending with \\r may cause problems", PM_WARNING_LEVEL_DEFAULT },
|
||||
[PM_WARN_UNEXPECTED_CARRIAGE_RETURN] = { "encountered \\r in middle of line, treated as a mere space", PM_WARNING_LEVEL_DEFAULT },
|
||||
[PM_WARN_UNREACHABLE_STATEMENT] = { "statement not reached", PM_WARNING_LEVEL_VERBOSE },
|
||||
|
|
|
@ -64,6 +64,15 @@ module Prism
|
|||
assert_warning("if true\nelsif\nfalse; end", "end of line")
|
||||
end
|
||||
|
||||
def test_shareable_constant_value
|
||||
assert_warning("foo # shareable_constant_value: none", "ignored")
|
||||
assert_warning("\v # shareable_constant_value: none", "ignored")
|
||||
|
||||
refute_warning("# shareable_constant_value: none")
|
||||
refute_warning(" # shareable_constant_value: none")
|
||||
refute_warning("\t\t# shareable_constant_value: none")
|
||||
end
|
||||
|
||||
def test_string_in_predicate
|
||||
assert_warning("if 'foo'; end", "string")
|
||||
assert_warning("if \"\#{foo}\"; end", "string")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue