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

ruby-changes:55748

From: Nobuyoshi <ko1@a...>
Date: Sat, 18 May 2019 09:36:51 +0900 (JST)
Subject: [ruby-changes:55748] Nobuyoshi Nakada: c4bad9f74e (trunk): Distinguish pre-condition and post-condition loops

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

From c4bad9f74e432572b80c24c7f1c519c5cc4c59a2 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 18 May 2019 09:35:40 +0900
Subject: Distinguish pre-condition and post-condition loops


diff --git a/ast.c b/ast.c
index 3e25c89..2d21909 100644
--- a/ast.c
+++ b/ast.c
@@ -374,7 +374,8 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L374
         goto loop;
       case NODE_UNTIL:
       loop:
-        return rb_ary_new_from_node_args(ast, 2, node->nd_cond, node->nd_body);
+        return rb_ary_push(rb_ary_new_from_node_args(ast, 2, node->nd_cond, node->nd_body),
+                           (node->nd_state ? Qtrue : Qfalse));
       case NODE_ITER:
       case NODE_FOR:
         return rb_ary_new_from_node_args(ast, 2, node->nd_iter, node->nd_body);
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index 974dfb7..7809be0 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -278,4 +278,16 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L278
     assert_equal(:LIT, body.type)
     assert_equal([1], body.children)
   end
+
+  def test_while
+    node = RubyVM::AbstractSyntaxTree.parse('1 while 1')
+    _, _, body = *node.children
+    assert_equal(:WHILE, body.type)
+    type1 = body.children[2]
+    node = RubyVM::AbstractSyntaxTree.parse('begin 1 end while 1')
+    _, _, body = *node.children
+    assert_equal(:WHILE, body.type)
+    type2 = body.children[2]
+    assert_not_equal(type1, type2)
+  end
 end
-- 
cgit v0.10.2


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

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