Repository: ruby/prism
Pull request #3019 (2024-08-27 20:42:41)

Add `contains_splat` flag
If we have a splat, add a flag for it named `contains_splat`.


Patch:
diff --git a/config.yml b/config.yml
index d26af5c6..88fccce4 100644
--- a/config.yml
+++ b/config.yml
@@ -651,6 +651,8 @@ flags:
         comment: "if arguments contain keywords"
       - name: CONTAINS_KEYWORD_SPLAT
         comment: "if arguments contain keyword splat"
+      - name: CONTAINS_SPLAT
+        comment: "if arguments contain splat"
     comment: Flags for arguments nodes.
   - name: ArrayNodeFlags
     values:
diff --git a/src/prism.c b/src/prism.c
index 5b8e256a..eca764bc 100644
--- a/src/prism.c
+++ b/src/prism.c
@@ -2062,6 +2062,10 @@ pm_arguments_node_arguments_append(pm_arguments_node_t *node, pm_node_t *argumen
 
     node->base.location.end = argument->location.end;
     pm_node_list_append(&node->arguments, argument);
+
+    if (PM_NODE_TYPE_P(argument, PM_SPLAT_NODE)) {
+        pm_node_flag_set((pm_node_t *) node, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_SPLAT);
+    }
 }
 
 /**


Test patch:
diff --git a/test/prism/snapshots/arrays.txt b/test/prism/snapshots/arrays.txt
index a73c56ac..73154943 100644
--- a/test/prism/snapshots/arrays.txt
+++ b/test/prism/snapshots/arrays.txt
@@ -1418,7 +1418,7 @@
         │   │           ├── opening_loc: (108,11)-(108,12) = "["
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (108,12)-(108,13))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ SplatNode (location: (108,12)-(108,13))
         │   │           │           ├── flags: ∅
@@ -1476,7 +1476,7 @@
         │   │           ├── opening_loc: (110,11)-(110,12) = "["
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (110,12)-(110,16))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 2)
         │   │           │       ├── @ IntegerNode (location: (110,12)-(110,13))
         │   │           │       │   ├── flags: static_literal, decimal
@@ -1537,7 +1537,7 @@
         │   │           ├── opening_loc: (112,11)-(112,12) = "["
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (112,12)-(112,18))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 2)
         │   │           │       ├── @ SplatNode (location: (112,12)-(112,13))
         │   │           │       │   ├── flags: ∅
@@ -1598,7 +1598,7 @@
         │   │           ├── opening_loc: (114,11)-(114,12) = "["
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (114,12)-(114,21))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 3)
         │   │           │       ├── @ IntegerNode (location: (114,12)-(114,13))
         │   │           │       │   ├── flags: static_literal, decimal
@@ -1660,7 +1660,7 @@
         │   │           ├── opening_loc: (116,11)-(116,12) = "["
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (116,12)-(116,13))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ SplatNode (location: (116,12)-(116,13))
         │   │           │           ├── flags: ∅
@@ -1722,7 +1722,7 @@
         │   │           ├── opening_loc: (118,11)-(118,12) = "["
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (118,12)-(118,16))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 2)
         │   │           │       ├── @ IntegerNode (location: (118,12)-(118,13))
         │   │           │       │   ├── flags: static_literal, decimal
@@ -1793,7 +1793,7 @@
         │   │   │   │   ├── opening_loc: (120,21)-(120,22) = "["
         │   │   │   │   ├── arguments:
         │   │   │   │   │   @ ArgumentsNode (location: (120,22)-(120,23))
-        │   │   │   │   │   ├── flags: ∅
+        │   │   │   │   │   ├── flags: contains_splat
         │   │   │   │   │   └── arguments: (length: 1)
         │   │   │   │   │       └── @ SplatNode (location: (120,22)-(120,23))
         │   │   │   │   │           ├── flags: ∅
@@ -1861,7 +1861,7 @@
             │   │   │   ├── opening_loc: (122,21)-(122,22) = "["
             │   │   │   ├── arguments:
             │   │   │   │   @ ArgumentsNode (location: (122,22)-(122,26))
-            │   │   │   │   ├── flags: ∅
+            │   │   │   │   ├── flags: contains_splat
             │   │   │   │   └── arguments: (length: 2)
             │   │   │   │       ├── @ IntegerNode (location: (122,22)-(122,23))
             │   │   │   │       │   ├── flags: static_literal, decimal
diff --git a/test/prism/snapshots/constants.txt b/test/prism/snapshots/constants.txt
index 3246ff80..e1aada8e 100644
--- a/test/prism/snapshots/constants.txt
+++ b/test/prism/snapshots/constants.txt
@@ -99,7 +99,7 @@
         │   ├── opening_loc: ∅
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (15,4)-(15,8))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (15,4)-(15,8))
         │   │           ├── flags: ∅
@@ -183,7 +183,7 @@
         │   ├── opening_loc: ∅
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (21,9)-(21,13))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (21,9)-(21,13))
         │   │           ├── flags: ∅
diff --git a/test/prism/snapshots/method_calls.txt b/test/prism/snapshots/method_calls.txt
index 4bf8f3c7..0d1b39b2 100644
--- a/test/prism/snapshots/method_calls.txt
+++ b/test/prism/snapshots/method_calls.txt
@@ -414,7 +414,7 @@
         │   ├── opening_loc: (35,1)-(35,2) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (35,2)-(35,7))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (35,2)-(35,7))
         │   │           ├── flags: ∅
@@ -763,7 +763,7 @@
         │   ├── opening_loc: (58,3)-(58,4) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (58,4)-(58,9))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (58,4)-(58,9))
         │   │           ├── flags: ∅
@@ -2453,7 +2453,7 @@
         │   │           ├── opening_loc: ∅
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (149,12)-(149,13))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ SplatNode (location: (149,12)-(149,13))
         │   │           │           ├── flags: ∅
diff --git a/test/prism/snapshots/methods.txt b/test/prism/snapshots/methods.txt
index 42f87b75..e3fcfe0a 100644
--- a/test/prism/snapshots/methods.txt
+++ b/test/prism/snapshots/methods.txt
@@ -1041,7 +1041,7 @@
         │   │           ├── opening_loc: (110,11)-(110,12) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (110,12)-(110,13))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ SplatNode (location: (110,12)-(110,13))
         │   │           │           ├── flags: ∅
diff --git a/test/prism/snapshots/return.txt b/test/prism/snapshots/return.txt
index 8c01ee43..fc2bd70f 100644
--- a/test/prism/snapshots/return.txt
+++ b/test/prism/snapshots/return.txt
@@ -54,7 +54,7 @@
         │   ├── keyword_loc: (5,0)-(5,6) = "return"
         │   └── arguments:
         │       @ ArgumentsNode (location: (5,7)-(5,9))
-        │       ├── flags: ∅
+        │       ├── flags: contains_splat
         │       └── arguments: (length: 1)
         │           └── @ SplatNode (location: (5,7)-(5,9))
         │               ├── flags: ∅
diff --git a/test/prism/snapshots/unparser/corpus/literal/assignment.txt b/test/prism/snapshots/unparser/corpus/literal/assignment.txt
index aa1d1037..4e4ed86e 100644
--- a/test/prism/snapshots/unparser/corpus/literal/assignment.txt
+++ b/test/prism/snapshots/unparser/corpus/literal/assignment.txt
@@ -399,7 +399,7 @@
         │   │   │   ├── opening_loc: (15,2)-(15,3) = "["
         │   │   │   ├── arguments:
         │   │   │   │   @ ArgumentsNode (location: (15,3)-(15,7))
-        │   │   │   │   ├── flags: ∅
+        │   │   │   │   ├── flags: contains_splat
         │   │   │   │   └── arguments: (length: 1)
         │   │   │   │       └── @ SplatNode (location: (15,3)-(15,7))
         │   │   │   │           ├── flags: ∅
@@ -723,7 +723,7 @@
         │   ├── opening_loc: (29,3)-(29,4) = "["
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (29,4)-(29,19))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 2)
         │   │       ├── @ SplatNode (location: (29,4)-(29,10))
         │   │       │   ├── flags: ∅
diff --git a/test/prism/snapshots/unparser/corpus/literal/send.txt b/test/prism/snapshots/unparser/corpus/literal/send.txt
index 56d13740..dc4d2be7 100644
--- a/test/prism/snapshots/unparser/corpus/literal/send.txt
+++ b/test/prism/snapshots/unparser/corpus/literal/send.txt
@@ -890,7 +890,7 @@
         │   ├── opening_loc: (52,3)-(52,4) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (52,4)-(52,9))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (52,4)-(52,9))
         │   │           ├── flags: ∅
@@ -931,7 +931,7 @@
         │   ├── opening_loc: (53,3)-(53,4) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (53,4)-(53,14))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (53,4)-(53,14))
         │   │           ├── flags: ∅
@@ -1000,7 +1000,7 @@
         │   ├── opening_loc: (56,3)-(56,4) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (56,4)-(56,14))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 2)
         │   │       ├── @ CallNode (location: (56,4)-(56,7))
         │   │       │   ├── flags: variable_call, ignore_visibility
@@ -1123,7 +1123,7 @@
         │   ├── opening_loc: (59,7)-(59,8) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (59,8)-(59,25))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 3)
         │   │       ├── @ SplatNode (location: (59,8)-(59,13))
         │   │       │   ├── flags: ∅
@@ -1184,7 +1184,7 @@
         │   ├── opening_loc: (60,7)-(60,8) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (60,8)-(60,13))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (60,8)-(60,13))
         │   │           ├── flags: ∅
@@ -1221,7 +1221,7 @@
         │   ├── opening_loc: (61,7)-(61,8) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (61,8)-(61,18))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 2)
         │   │       ├── @ SplatNode (location: (61,8)-(61,13))
         │   │       │   ├── flags: ∅
@@ -1415,7 +1415,7 @@
         │   ├── opening_loc: (65,7)-(65,8) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (65,8)-(65,18))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 2)
         │   │       ├── @ CallNode (location: (65,8)-(65,11))
         │   │       │   ├── flags: variable_call, ignore_visibility
@@ -1462,7 +1462,7 @@
         │   ├── opening_loc: (66,7)-(66,8) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (66,8)-(66,18))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 2)
         │   │       ├── @ CallNode (location: (66,8)-(66,11))
         │   │       │   ├── flags: variable_call, ignore_visibility
@@ -1773,7 +1773,7 @@
         │   ├── opening_loc: (73,3)-(73,4) = "["
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (73,4)-(73,8))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (73,4)-(73,8))
         │   │           ├── flags: ∅
@@ -2136,7 +2136,7 @@
         │   │           ├── opening_loc: (80,13)-(80,14) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (80,14)-(80,16))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ SplatNode (location: (80,14)-(80,16))
         │   │           │           ├── flags: ∅
diff --git a/test/prism/snapshots/unparser/corpus/literal/since/32.txt b/test/prism/snapshots/unparser/corpus/literal/since/32.txt
index efd01196..2b126a0c 100644
--- a/test/prism/snapshots/unparser/corpus/literal/since/32.txt
+++ b/test/prism/snapshots/unparser/corpus/literal/since/32.txt
@@ -99,7 +99,7 @@
         │   │           ├── opening_loc: (6,5)-(6,6) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (6,6)-(6,17))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_splat
         │   │           │   └── arguments: (length: 2)
         │   │           │       ├── @ LocalVariableReadNode (location: (6,6)-(6,14))
         │   │           │       │   ├── flags: ∅
diff --git a/test/prism/snapshots/whitequark/args_args_star.txt b/test/prism/snapshots/whitequark/args_args_star.txt
index 85830e7f..32f8b6ba 100644
--- a/test/prism/snapshots/whitequark/args_args_star.txt
+++ b/test/prism/snapshots/whitequark/args_args_star.txt
@@ -14,7 +14,7 @@
         │   ├── opening_loc: (1,3)-(1,4) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (1,4)-(1,13))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 2)
         │   │       ├── @ CallNode (location: (1,4)-(1,7))
         │   │       │   ├── flags: variable_call, ignore_visibility
@@ -51,7 +51,7 @@
             ├── opening_loc: (3,3)-(3,4) = "("
             ├── arguments:
             │   @ ArgumentsNode (location: (3,4)-(3,13))
-            │   ├── flags: ∅
+            │   ├── flags: contains_splat
             │   └── arguments: (length: 2)
             │       ├── @ CallNode (location: (3,4)-(3,7))
             │       │   ├── flags: variable_call, ignore_visibility
diff --git a/test/prism/snapshots/whitequark/args_star.txt b/test/prism/snapshots/whitequark/args_star.txt
index fc04bacc..488b113d 100644
--- a/test/prism/snapshots/whitequark/args_star.txt
+++ b/test/prism/snapshots/whitequark/args_star.txt
@@ -14,7 +14,7 @@
         │   ├── opening_loc: (1,3)-(1,4) = "("
         │   ├── arguments:
         │   │   @ ArgumentsNode (location: (1,4)-(1,8))
-        │   │   ├── flags: ∅
+        │   │   ├── flags: contains_splat
         │   │   └── arguments: (length: 1)
         │   │       └── @ SplatNode (location: (1,4)-(1,8))
         │   │           ├── flags: ∅
@@ -41,7 +41,7 @@
             ├── opening_loc: (3,3)-(3,4) = "("
             ├── arguments:
             │   @ ArgumentsNode (location: (3,4)-(3,8))
-            │   ├── flags: ∅
+            │   ├── flags: contains_splat
             │   └── arguments: (length: 1)
             │       └── @ SplatNode (location: (3,4)-(3,8))
             │           ├── flags: ∅
diff --git a/test/prism/snapshots/whitequark/forwarded_argument_with_restarg.txt b/test/prism/snapshots/whitequark/forwarded_argument_with_restarg.txt
index 3607930b..2dd95c6c 100644
--- a/test/prism/snapshots/whitequark/forwarded_argument_with_restarg.txt
+++ b/test/prism/snapshots/whitequark/forwarded_argument_with_restarg.txt
@@ -41,7 +41,7 @@
             │           ├── opening_loc: (1,25)-(1,26) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,26)-(1,37))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_splat
             │           │   └── arguments: (length: 2)
             │           │       ├── @ LocalVariableReadNode (location: (1,26)-(1,34))
             │           │       │   ├── flags: ∅
diff --git a/test/prism/snapshots/whitequark/forwarded_restarg.txt b/test/prism/snapshots/whitequark/forwarded_restarg.txt
index c0bdd05a..3e26b2b6 100644
--- a/test/prism/snapshots/whitequark/forwarded_restarg.txt
+++ b/test/prism/snapshots/whitequark/forwarded_restarg.txt
@@ -38,7 +38,7 @@
             │           ├── opening_loc: (1,15)-(1,16) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,16)-(1,17))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_splat
             │           │   └── arguments: (length: 1)
             │           │       └── @ SplatNode (location: (1,16)-(1,17))
             │           │           ├── flags: ∅