[前][次][番号順一覧][スレッド一覧]

ruby-changes:58593

From: Nobuyoshi <ko1@a...>
Date: Wed, 6 Nov 2019 12:45:58 +0900 (JST)
Subject: [ruby-changes:58593] 2fd465540f (master): Numbered parameter is an ID_LOCAL now [Bug #16293]

https://git.ruby-lang.org/ruby.git/commit/?id=2fd465540f

From 2fd465540f6dacaf16a8b679b6da000e90845a00 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 6 Nov 2019 12:45:11 +0900
Subject: Numbered parameter is an ID_LOCAL now [Bug #16293]


diff --git a/parse.y b/parse.y
index ac9146a..ef335c8 100644
--- a/parse.y
+++ b/parse.y
@@ -9960,12 +9960,6 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc) https://github.com/ruby/ruby/blob/trunk/parse.y#L9960
 
     }
     switch (id_type(id)) {
-      case ID_INTERNAL:
-	{
-	    int idx = vtable_included(p->lvtbl->args, id);
-	    if (idx) return NEW_DVAR(id, loc);
-	}
-	break;
       case ID_LOCAL:
 	if (dyna_in_block(p) && dvar_defined_ref(p, id, &vidp)) {
 	    if (NUMPARAM_ID_P(id) && numparam_nested_p(p)) return 0;
@@ -10195,8 +10189,6 @@ id_is_var(struct parser_params *p, ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L10189
 	switch (id & ID_SCOPE_MASK) {
 	  case ID_GLOBAL: case ID_INSTANCE: case ID_CONST: case ID_CLASS:
 	    return 1;
-	  case ID_INTERNAL:
-	    return vtable_included(p->lvtbl->args, id);
 	  case ID_LOCAL:
 	    if (dyna_in_block(p)) {
 		if (NUMPARAM_ID_P(id) || dvar_defined(p, id)) return 1;
@@ -10452,6 +10444,11 @@ assignable0(struct parser_params *p, ID id, const char **err) https://github.com/ruby/ruby/blob/trunk/parse.y#L10444
     switch (id_type(id)) {
       case ID_LOCAL:
 	if (dyna_in_block(p)) {
+	    if (p->max_numparam > NO_PARAM && NUMPARAM_ID_P(id)) {
+		compile_error(p, "Can't assign to numbered parameter _%d",
+			      NUMPARAM_ID_TO_IDX(id));
+		return -1;
+	    }
 	    if (dvar_curr(p, id)) return NODE_DASGN_CURR;
 	    if (dvar_defined(p, id)) return NODE_DASGN;
 	    if (local_id(p, id)) return NODE_LASGN;
@@ -10470,15 +10467,6 @@ assignable0(struct parser_params *p, ID id, const char **err) https://github.com/ruby/ruby/blob/trunk/parse.y#L10467
 	*err = "dynamic constant assignment";
 	return -1;
       case ID_CLASS: return NODE_CVASGN;
-      case ID_INTERNAL:
-	{
-	    int idx = vtable_included(p->lvtbl->args, id);
-	    if (idx) {
-		compile_error(p, "Can't assign to numbered parameter @%d", idx);
-		break;
-	    }
-	}
-	/* fallthru */
       default:
 	compile_error(p, "identifier %"PRIsVALUE" is not valid to set", rb_id2str(id));
     }
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index b55e579..ef1e242 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1455,6 +1455,7 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1455
     assert_syntax_error('->x=_1{}', /ordinary parameter is defined/)
     assert_syntax_error('-> {_1; -> {_2}}', /numbered parameter is already used/)
     assert_syntax_error('-> {-> {_1}; _2}', /numbered parameter is already used/)
+    assert_syntax_error('proc {_1; _1 = nil}', /Can't assign to numbered parameter _1/)
     assert_warn(/`_1' is used as numbered parameter/) {eval('proc {_1 = nil}')}
     assert_warn(/`_2' is used as numbered parameter/) {eval('_2=1')}
     assert_raise_with_message(NameError, /undefined local variable or method `_1'/) {
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]