]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix edge case of formatting instability, b1189
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 7 Aug 2021 14:37:00 +0000 (07:37 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 7 Aug 2021 14:37:00 +0000 (07:37 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 6009a0b767c718736294020b14860d96b5482c5a..2d53b292f4dcac64a010f54d9bf6040f10a06c13 100644 (file)
@@ -7029,6 +7029,37 @@ find(
 --paren-vertical-tightness=1
 --weld-nested-containers
 
+==> b1189.in <==
+#S1
+if ($ON_EBCDIC)
+{
+    delete @Encode::ExtModule{ qw(euc-cn gb2312 gb12345 gbk cp936 iso-ir-165 MacChineseSimp
+     euc-jp iso-2022-jp 7bit-jis shiftjis MacJapanese cp932
+     euc-kr ksc5601 cp949 MacKorean
+     big5      big5-hkscs cp950 MacChineseTrad
+     gb18030 big5plus euc-tw)
+    };
+}
+
+#S2
+if ($ON_EBCDIC)
+{   delete @Encode::ExtModule{
+        qw(euc-cn gb2312 gb12345 gbk cp936 iso-ir-165 MacChineseSimp
+     euc-jp iso-2022-jp 7bit-jis shiftjis MacJapanese cp932
+     euc-kr ksc5601 cp949 MacKorean
+     big5      big5-hkscs cp950 MacChineseTrad
+     gb18030 big5plus euc-tw)
+    };
+}
+
+==> b1189.par <==
+--block-brace-vertical-tightness=1
+--continuation-indentation=7
+--nodelete-old-newlines
+--maximum-line-length=99
+--notrim-qw
+--weld-nested-containers
+
 ==> b120.in <==
 # Same as bug96
 # State 1
index 587cf853a3319fea4f3dc2b84aaa99db87a87a25..47887f9534854359d49817c82bd50b6330944d7d 100644 (file)
@@ -8476,6 +8476,19 @@ sub weld_nested_quotes {
             my $is_old_weld =
               ( $iline_oo == $iline_io && $iline_ic == $iline_oc );
 
+            # Fix for case b1189. If quote is marked as type 'Q' then only weld
+            # if the two closing tokens are on the same input line.  Otherwise,
+            # the closing line will be output earlier in the pipeline than
+            # other CODE lines and welding will not actually occur. This will
+            # leave a half-welded structure with potential formatting
+            # instability.  This might be fixed by adding a check for a weld on
+            # a closing Q token and sending it down the normal channel, but it
+            # would complicate the code and is potentially risky.
+            next
+              if (!$is_old_weld
+                && $next_type eq 'Q'
+                && $iline_ic != $iline_oc );
+
             # If welded, the line must not exceed allowed line length
             ( my $ok_to_weld, $maximum_text_length, $starting_lentot, my $msg )
               = $self->setup_new_weld_measurements( $Kouter_opening,
index 14066e48302ea5d3f430ba1b2d6c6746e7d15014..90c55bb3e572afb0da44fbb0dfe19b5fe0b24ccb 100644 (file)
@@ -2,6 +2,65 @@
 
 =over 4
 
+=item B<Fix edge case of formatting instability, b1189>.
+
+Testing with random parameters produced a case of unstable formatting involving
+welding with parameter -notrim-qw.  The problem was that the -notrim-qw flag
+converts a qw quote into a quote with fixed leading whitespace.
+The lines of these types of quotes which have no other code are are output early
+in the formatting process, since they have a fixed format, so welding does not work.
+In particular, the closing tokens cannot be welded if they are on a separate line.
+This also holds for all types of non-qw quotes.  So welding can only be done
+if the first and last lines of a non-qw quote contain other code.   A check for
+this was added.
+
+For example, in the following snippet the terminal '}' is alone on a line:
+
+    is eval(q{
+        $[ = 3;
+        BEGIN { my $x = "foo\x{666}"; $x =~ /foo\p{Alnum}/; }
+        $t[3];
+    }
+    ), "a";
+
+# In the previous version this was half-welded:
+# OLD: perltidy -wn -sil=0
+
+    is eval( q{
+        $[ = 3;
+        BEGIN { my $x = "foo\x{666}"; $x =~ /foo\p{Alnum}/; }
+        $t[3];
+    }
+      ),
+      "a";
+
+The new check avoids welding in this case, giving
+
+    # NEW: perltidy -wn -sil=0
+    is eval(
+        q{
+        $[ = 3;
+        BEGIN { my $x = "foo\x{666}"; $x =~ /foo\p{Alnum}/; }
+        $t[3];
+    }
+      ),
+      "a";
+
+Welding can still be done if the opening and closing container tokens
+have other code.  For example, welding can be done for the following snippet:
+
+    is eval(q{
+        $[ = 3;
+        BEGIN { my $x = "foo\x{666}"; $x =~ /foo\p{Alnum}/; }
+        $t[3];
+    }), "a";
+
+And welding can still be done on all qw quotes unless the -notrim-qw flag is set.
+
+This fixes case b1189.
+
+7 Aug 2021.
+
 =item B<Fix edge cases of formatting instability, b1187 b1188>.
 
 Testing with random parameters produced some cases of instability
@@ -10,7 +69,7 @@ involved an interaction between the formatter and vertical aligner.
 
 This fixes cases b1187 and b1188.
 
-3 Aug 2021.
+3 Aug 2021, 5be949b.
 
 =item B<Fix edge case of formatting instability, b1186>.
 
@@ -19,7 +78,7 @@ parameter -lp -pvt=n and a short maximum line length.
 
 This fixes case b1186.
 
-2 Aug 2021.
+2 Aug 2021, f3dbee1.
 
 =item B<Fix edge case of formatting instability, b1185>.
 
@@ -28,7 +87,7 @@ parameters -wn, -vt=2, -lp and a short maximum line length.
 
 This fixes case b1185.
 
-1 Aug 2021.
+1 Aug 2021, d2ab2b7.
 
 =item B<Fix edge case of formatting instability, b1183>.
 
@@ -37,7 +96,7 @@ parameters -wn, -vt=n, -lp. This update fixes the problem.
 
 This fixes case b1183.
 
-30 Jul 2021.
+30 Jul 2021, 055650b.
 
 =item B<Fix edge case of formatting instability, b1184>.
 
@@ -46,7 +105,7 @@ a tripple weld with parameters -wn, -vt=n, -lp. This update fixes the problem.
 
 This fixes case b1184.
 
-29 Jul 2021.
+29 Jul 2021, 6dd53fb.
 
 =item B<Fix edge case of formatting instability, b1182>.
 
@@ -56,7 +115,7 @@ problem.
 
 This fixes case b1182.
 
-28 Jul 2021.
+28 Jul 2021, 01d6c40.
 
 =item B<Fix edge case of formatting instability>.