summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y15
-rw-r--r--test/ruby/test_rubyoptions.rb9
3 files changed, 22 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 4ac59ce341..7c2f8d2e71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Jul 8 07:36:19 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (shadowing_lvar_gen, warn_unused_var): no warnings for
+ variables starting with _. [ruby-core:46160][Feature #6693]
+
Sat Jul 7 23:07:30 2012 CHIKANAGA Tomoyuki <nagachika@ruby-lang.org>
* test/csv/test_features.rb: add require for Tempfile.
diff --git a/parse.y b/parse.y
index c10099126f..0853d1e790 100644
--- a/parse.y
+++ b/parse.y
@@ -8595,12 +8595,23 @@ assignable_gen(struct parser_params *parser, ID id, NODE *val)
#undef parser_yyerror
}
+static int
+is_private_local_id(ID name)
+{
+ VALUE s;
+ if (name == idUScore) return 1;
+ if (!is_local_id(name)) return 0;
+ s = rb_id2str(name);
+ if (!s) return 0;
+ return RSTRING_PTR(s)[0] == '_';
+}
+
#define LVAR_USED ((int)1 << (sizeof(int) * CHAR_BIT - 1))
static ID
shadowing_lvar_gen(struct parser_params *parser, ID name)
{
- if (idUScore == name) return name;
+ if (is_private_local_id(name)) return name;
if (dyna_in_block()) {
if (dvar_curr(name)) {
yyerror("duplicated argument name");
@@ -9324,7 +9335,7 @@ warn_unused_var(struct parser_params *parser, struct local_vars *local)
}
for (i = 0; i < cnt; ++i) {
if (!v[i] || (u[i] & LVAR_USED)) continue;
- if (idUScore == v[i]) continue;
+ if (is_private_local_id(v[i])) continue;
rb_compile_warn(ruby_sourcefile, (int)u[i], "assigned but unused variable - %s", rb_id2name(v[i]));
}
}
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 62be634c47..1f2732cebb 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -497,7 +497,8 @@ class TestRubyOptions < Test::Unit::TestCase
assert_in_out_err(["-we", "1.times do\n a=1\nend"], "", [], [], feature3446)
assert_in_out_err(["-we", "def foo\n 1.times do\n a=1\n end\nend"], "", [], ["-e:3: warning: assigned but unused variable - a"], feature3446)
assert_in_out_err(["-we", "def foo\n"" 1.times do |a| end\n""end"], "", [], [])
- assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], ["-e:2: warning: assigned but unused variable - _a"], feature3446)
+ feature6693 = '[ruby-core:46160]'
+ assert_in_out_err(["-we", "def foo\n _a=1\nend"], "", [], [], feature6693)
end
def test_shadowing_variable
@@ -509,11 +510,9 @@ class TestRubyOptions < Test::Unit::TestCase
["-e:3: warning: shadowing outer local variable - a",
"-e:2: warning: assigned but unused variable - a",
], bug4130)
+ feature6693 = '[ruby-core:46160]'
assert_in_out_err(["-we", "def foo\n"" _a=1\n"" 1.times do |_a| end\n""end"],
- "", [],
- ["-e:3: warning: shadowing outer local variable - _a",
- "-e:2: warning: assigned but unused variable - _a",
- ], bug4130)
+ "", [], [], feature6693)
end
def test_script_from_stdin