Repository: ruby/prism
Pull request #3051 (2024-09-11 16:29:29)

Add a flag for arguments that contain forwarding


Patch:
diff --git a/config.yml b/config.yml
index 585d17a4..1c00ef14 100644
--- a/config.yml
+++ b/config.yml
@@ -647,14 +647,16 @@ tokens:
 flags:
   - name: ArgumentsNodeFlags
     values:
+      - name: CONTAINS_FORWARDING
+        comment: "if the arguments contain forwarding"
       - name: CONTAINS_KEYWORDS
-        comment: "if arguments contain keywords"
+        comment: "if the arguments contain keywords"
       - name: CONTAINS_KEYWORD_SPLAT
-        comment: "if arguments contain keyword splat"
+        comment: "if the arguments contain a keyword splat"
       - name: CONTAINS_SPLAT
-        comment: "if arguments contain splat"
+        comment: "if the arguments contain a splat"
       - name: CONTAINS_MULTIPLE_SPLATS
-        comment: "if arguments contain multiple splats"
+        comment: "if the arguments contain multiple splats"
     comment: Flags for arguments nodes.
   - name: ArrayNodeFlags
     values:
diff --git a/src/prism.c b/src/prism.c
index 4edb57ad..5c81bbba 100644
--- a/src/prism.c
+++ b/src/prism.c
@@ -14180,6 +14180,7 @@ parse_arguments(pm_parser_t *parser, pm_arguments_t *arguments, bool accepts_for
 
                         argument = (pm_node_t *) pm_forwarding_arguments_node_create(parser, &parser->previous);
                         parse_arguments_append(parser, arguments, argument);
+                        pm_node_flag_set((pm_node_t *) arguments->arguments, PM_ARGUMENTS_NODE_FLAGS_CONTAINS_FORWARDING);
                         arguments->has_forwarding = true;
                         parsed_forwarding_arguments = true;
                         break;


Test patch:
diff --git a/test/prism/snapshots/methods.txt b/test/prism/snapshots/methods.txt
index af2defcb..07809991 100644
--- a/test/prism/snapshots/methods.txt
+++ b/test/prism/snapshots/methods.txt
@@ -1086,7 +1086,7 @@
         │   │           ├── opening_loc: (112,13)-(112,14) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (112,14)-(112,17))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (112,14)-(112,17))
         │   │           │           └── flags: ∅
@@ -1129,7 +1129,7 @@
         │   │           ├── opening_loc: (114,13)-(114,14) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (114,14)-(114,23))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 3)
         │   │           │       ├── @ IntegerNode (location: (114,14)-(114,15))
         │   │           │       │   ├── flags: static_literal, decimal
@@ -1382,7 +1382,7 @@
         │   │           │       │           ├── opening_loc: (136,19)-(136,20) = "("
         │   │           │       │           ├── arguments:
         │   │           │       │           │   @ ArgumentsNode (location: (136,20)-(136,23))
-        │   │           │       │           │   ├── flags: ∅
+        │   │           │       │           │   ├── flags: contains_forwarding
         │   │           │       │           │   └── arguments: (length: 1)
         │   │           │       │           │       └── @ ForwardingArgumentsNode (location: (136,20)-(136,23))
         │   │           │       │           │           └── flags: ∅
@@ -2095,7 +2095,7 @@
         │   │           ├── opening_loc: (178,5)-(178,6) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (178,6)-(178,9))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (178,6)-(178,9))
         │   │           │           └── flags: ∅
diff --git a/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt b/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt
index 905978bc..ababd94b 100644
--- a/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt
+++ b/test/prism/snapshots/seattlerb/defn_arg_forward_args.txt
@@ -38,7 +38,7 @@
             │           ├── opening_loc: (1,16)-(1,17) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,17)-(1,23))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 2)
             │           │       ├── @ LocalVariableReadNode (location: (1,17)-(1,18))
             │           │       │   ├── flags: ∅
diff --git a/test/prism/snapshots/seattlerb/defn_args_forward_args.txt b/test/prism/snapshots/seattlerb/defn_args_forward_args.txt
index ca03f79d..d6890494 100644
--- a/test/prism/snapshots/seattlerb/defn_args_forward_args.txt
+++ b/test/prism/snapshots/seattlerb/defn_args_forward_args.txt
@@ -44,7 +44,7 @@
             │           ├── opening_loc: (1,22)-(1,23) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,23)-(1,35))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 3)
             │           │       ├── @ SymbolNode (location: (1,23)-(1,27))
             │           │       │   ├── flags: static_literal, forced_us_ascii_encoding
diff --git a/test/prism/snapshots/seattlerb/defn_forward_args.txt b/test/prism/snapshots/seattlerb/defn_forward_args.txt
index 50fc32c0..58a97028 100644
--- a/test/prism/snapshots/seattlerb/defn_forward_args.txt
+++ b/test/prism/snapshots/seattlerb/defn_forward_args.txt
@@ -35,7 +35,7 @@
             │           ├── opening_loc: (1,13)-(1,14) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,14)-(1,17))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 1)
             │           │       └── @ ForwardingArgumentsNode (location: (1,14)-(1,17))
             │           │           └── flags: ∅
diff --git a/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt b/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt
index 8926f2cd..5d8e09f6 100644
--- a/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt
+++ b/test/prism/snapshots/seattlerb/defn_forward_args__no_parens.txt
@@ -35,7 +35,7 @@
             │           ├── opening_loc: (2,3)-(2,4) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (2,4)-(2,7))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 1)
             │           │       └── @ ForwardingArgumentsNode (location: (2,4)-(2,7))
             │           │           └── flags: ∅
diff --git a/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt b/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt
index 5927016b..eaa10610 100644
--- a/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt
+++ b/test/prism/snapshots/whitequark/endless_method_forwarded_args_legacy.txt
@@ -35,7 +35,7 @@
             │           ├── opening_loc: (1,18)-(1,19) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,19)-(1,22))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 1)
             │           │       └── @ ForwardingArgumentsNode (location: (1,19)-(1,22))
             │           │           └── flags: ∅
diff --git a/test/prism/snapshots/whitequark/forward_arg.txt b/test/prism/snapshots/whitequark/forward_arg.txt
index b8c22d08..3879314f 100644
--- a/test/prism/snapshots/whitequark/forward_arg.txt
+++ b/test/prism/snapshots/whitequark/forward_arg.txt
@@ -35,7 +35,7 @@
             │           ├── opening_loc: (1,17)-(1,18) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,18)-(1,21))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 1)
             │           │       └── @ ForwardingArgumentsNode (location: (1,18)-(1,21))
             │           │           └── flags: ∅
diff --git a/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt b/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt
index 20c84862..ea36abae 100644
--- a/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt
+++ b/test/prism/snapshots/whitequark/forward_arg_with_open_args.txt
@@ -41,7 +41,7 @@
         │   │           │           ├── opening_loc: (2,5)-(2,6) = "("
         │   │           │           ├── arguments:
         │   │           │           │   @ ArgumentsNode (location: (2,6)-(2,9))
-        │   │           │           │   ├── flags: ∅
+        │   │           │           │   ├── flags: contains_forwarding
         │   │           │           │   └── arguments: (length: 1)
         │   │           │           │       └── @ ForwardingArgumentsNode (location: (2,6)-(2,9))
         │   │           │           │           └── flags: ∅
@@ -92,7 +92,7 @@
         │   │           │           ├── opening_loc: (5,17)-(5,18) = "("
         │   │           │           ├── arguments:
         │   │           │           │   @ ArgumentsNode (location: (5,18)-(5,21))
-        │   │           │           │   ├── flags: ∅
+        │   │           │           │   ├── flags: contains_forwarding
         │   │           │           │   └── arguments: (length: 1)
         │   │           │           │       └── @ ForwardingArgumentsNode (location: (5,18)-(5,21))
         │   │           │           │           └── flags: ∅
@@ -162,7 +162,7 @@
         │   │           ├── opening_loc: (10,16)-(10,17) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (10,17)-(10,20))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (10,17)-(10,20))
         │   │           │           └── flags: ∅
@@ -208,7 +208,7 @@
         │   │           ├── opening_loc: (13,5)-(13,6) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (13,6)-(13,9))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (13,6)-(13,9))
         │   │           │           └── flags: ∅
@@ -254,7 +254,7 @@
         │   │           ├── opening_loc: (16,19)-(16,20) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (16,20)-(16,23))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (16,20)-(16,23))
         │   │           │           └── flags: ∅
@@ -343,7 +343,7 @@
         │   │           ├── opening_loc: (22,5)-(22,6) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (22,6)-(22,9))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (22,6)-(22,9))
         │   │           │           └── flags: ∅
@@ -395,7 +395,7 @@
         │   │           ├── opening_loc: (25,23)-(25,24) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (25,24)-(25,27))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (25,24)-(25,27))
         │   │           │           └── flags: ∅
@@ -441,7 +441,7 @@
             │           ├── opening_loc: (27,19)-(27,20) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (27,20)-(27,23))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 1)
             │           │       └── @ ForwardingArgumentsNode (location: (27,20)-(27,23))
             │           │           └── flags: ∅
diff --git a/test/prism/snapshots/whitequark/forward_args_legacy.txt b/test/prism/snapshots/whitequark/forward_args_legacy.txt
index 6fd9c536..2fda9338 100644
--- a/test/prism/snapshots/whitequark/forward_args_legacy.txt
+++ b/test/prism/snapshots/whitequark/forward_args_legacy.txt
@@ -35,7 +35,7 @@
         │   │           ├── opening_loc: (1,17)-(1,18) = "("
         │   │           ├── arguments:
         │   │           │   @ ArgumentsNode (location: (1,18)-(1,21))
-        │   │           │   ├── flags: ∅
+        │   │           │   ├── flags: contains_forwarding
         │   │           │   └── arguments: (length: 1)
         │   │           │       └── @ ForwardingArgumentsNode (location: (1,18)-(1,21))
         │   │           │           └── flags: ∅
@@ -100,7 +100,7 @@
             │           ├── lparen_loc: (5,19)-(5,20) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (5,20)-(5,23))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 1)
             │           │       └── @ ForwardingArgumentsNode (location: (5,20)-(5,23))
             │           │           └── flags: ∅
diff --git a/test/prism/snapshots/whitequark/trailing_forward_arg.txt b/test/prism/snapshots/whitequark/trailing_forward_arg.txt
index 3cb3f8ae..75fce37a 100644
--- a/test/prism/snapshots/whitequark/trailing_forward_arg.txt
+++ b/test/prism/snapshots/whitequark/trailing_forward_arg.txt
@@ -41,7 +41,7 @@
             │           ├── opening_loc: (1,23)-(1,24) = "("
             │           ├── arguments:
             │           │   @ ArgumentsNode (location: (1,24)-(1,34))
-            │           │   ├── flags: ∅
+            │           │   ├── flags: contains_forwarding
             │           │   └── arguments: (length: 3)
             │           │       ├── @ LocalVariableReadNode (location: (1,24)-(1,25))
             │           │       │   ├── flags: ∅