From f8f0beca9eff3438fad2537f2b1bc91615508cda Mon Sep 17 00:00:00 2001
From: Steve Hancock <perltidy@users.sourceforge.net>
Date: Thu, 28 Apr 2022 11:53:54 -0700
Subject: [PATCH] adjust weld rules to fix issue b1339

---
 dev-bin/run_convergence_tests.pl.data | 34 +++++++++++++++++++++++++++
 lib/Perl/Tidy/Formatter.pm            |  8 ++++---
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data
index fe7aeeec..1276458f 100644
--- a/dev-bin/run_convergence_tests.pl.data
+++ b/dev-bin/run_convergence_tests.pl.data
@@ -9802,6 +9802,40 @@ params =>
 --space-function-paren
 --weld-nested-containers
 
+==> b1339.in <==
+# S1
+   $LANGUAGE{'groff'}={
+                       'filename'=>'\\.groff$',
+                       'regex'=>'',
+                       'patterns'=>[
+                                    {
+                                     'name'=>'comment',
+                                     'regex'=>'\\\\".*?$',
+                                     'style'=>'comment',
+                                     'childregex'=>[]
+                                    }
+                       ]
+   };
+
+# S2
+   $LANGUAGE{'groff'}={
+        'filename'=>'\\.groff$',
+        'regex'=>'',
+        'patterns'=>[{'name'=>'comment','regex'=>'\\\\".*?$','style'=>'comment','childregex'=>[]}]
+   };
+
+==> b1339.par <==
+--noadd-whitespace
+--brace-vertical-tightness-closing=1
+--comma-arrow-breakpoints=0
+--continuation-indentation=8
+--extended-line-up-parentheses
+--ignore-old-breakpoints
+--indent-columns=3
+--maximum-line-length=98
+--square-bracket-vertical-tightness=2
+--weld-nested-containers
+
 ==> b140.in <==
 $cmd[ $i ]=[
 	 $s, $e, $cmd, \@hunk, $i ] ;
diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm
index 534304d2..ed5321e1 100644
--- a/lib/Perl/Tidy/Formatter.pm
+++ b/lib/Perl/Tidy/Formatter.pm
@@ -8744,9 +8744,11 @@ sub weld_nested_containers {
     # Setup hash needed for RULE 2B involving -lp -wn -vt=2
     # Note: this could be changed in the future to include -vt=1 and -vt=2
     # but for now only -vt=2 has caused instabilities with -wn.
+    # Note: used all keys for b1338, but switched to just '(' to fix b1339.
     my %no_weld_to_one_line_container;
     if ($rOpts_line_up_parentheses) {
-        foreach ( keys %opening_vertical_tightness ) {
+        ##foreach ( keys %opening_vertical_tightness ) {
+        foreach ( '(' ) {
             if ( $opening_vertical_tightness{$_} == 2 ) {
                 $no_weld_to_one_line_container{$_} = 1;
             }
@@ -9153,8 +9155,8 @@ EOM
         }
 
         # DO-NOT-WELD RULE 2B: Turn off welding to a *one-line container for* an
-        # opening token which uses both -lp indentation and -vt=2.  See issue
-        # b1338. Also see related issue b1183 involving welds and -vt>0.
+        # opening token which uses both -lp indentation and -vt=2.  See issues
+        # b1338, b1339. Also see related issue b1183 involving welds and -vt>0.
         if (  !$do_not_weld_rule
             && %no_weld_to_one_line_container
             && $iline_io == $iline_ic
-- 
2.39.5