From 6ec4d203f7aaf9737b78b9d90de7865004c900d8 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Mon, 1 Jan 2024 10:17:08 +0900 Subject: [PATCH] Warn "literal in condition" for `__LINE__` Print warning for a code like ```ruby if __LINE__ end # => warning: literal in condition ``` --- parse.y | 6 ++++++ test/ruby/test_syntax.rb | 3 +++ 2 files changed, 9 insertions(+) diff --git a/parse.y b/parse.y index 8dd5e470a3..9791d155af 100644 --- a/parse.y +++ b/parse.y @@ -14260,6 +14260,12 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l else { SWITCH_BY_COND_TYPE(type, warning, ""); } + break; + + case NODE_LINE: + SWITCH_BY_COND_TYPE(type, warning, ""); + break; + default: break; } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 286a820b02..5e277c8d8e 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1216,6 +1216,9 @@ eom assert_warning(/literal in condition/) do eval('1 if 1') end + assert_warning(/literal in condition/) do + eval('1 if __LINE__') + end assert_warning(/symbol literal in condition/) do eval('1 if :foo') end