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

The same warning for static symbol literal

This commit is contained in:
Nobuyoshi Nakada 2021-10-04 12:15:27 +09:00
parent da139317a5
commit 28392d3045
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
2 changed files with 7 additions and 3 deletions

View file

@ -11758,6 +11758,7 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l
break;
case NODE_DSYM:
warn_symbol:
SWITCH_BY_COND_TYPE(type, warning, "symbol ")
break;
@ -11770,6 +11771,9 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l
node->nd_lit == Qfalse) {
/* booleans are OK, e.g., while true */
}
else if (SYMBOL_P(node->nd_lit)) {
goto warn_symbol;
}
else {
SWITCH_BY_COND_TYPE(type, warning, "")
}

View file

@ -1061,16 +1061,16 @@ eom
end
def test_warning_literal_in_condition
assert_warn(/literal in condition/) do
assert_warn(/string literal in condition/) do
eval('1 if ""')
end
assert_warn(/literal in condition/) do
assert_warn(/regex literal in condition/) do
eval('1 if //')
end
assert_warning(/literal in condition/) do
eval('1 if 1')
end
assert_warning(/literal in condition/) do
assert_warning(/symbol literal in condition/) do
eval('1 if :foo')
end
assert_warning(/symbol literal in condition/) do