File 1172-erl_syntax-Proper-fix-for-the-bug-that-failed-to-pre.patch of Package erlang

From c62b33d651591e5a15aec916008f82f733594fd6 Mon Sep 17 00:00:00 2001
From: Richard Carlsson <carlsson.richard@gmail.com>
Date: Mon, 30 Dec 2024 20:43:57 +0100
Subject: [PATCH 2/4] erl_syntax: Proper fix for the bug that failed to
 preserve annotations when reverting `#wrapper` nodes. Makes revert slightly
 more efficient by using pattern matching instead of the is_tree/1 function.

---
 lib/syntax_tools/src/erl_syntax.erl | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lib/syntax_tools/src/erl_syntax.erl b/lib/syntax_tools/src/erl_syntax.erl
index e47d513934..930e1c6307 100644
--- a/lib/syntax_tools/src/erl_syntax.erl
+++ b/lib/syntax_tools/src/erl_syntax.erl
@@ -7462,12 +7462,8 @@ _See also: _[//stdlib/erl_parse](`m:erl_parse`), `revert_forms/1`.
 -spec revert(syntaxTree()) -> syntaxTree().
 
 revert(Node) ->
-    case is_tree(Node) of
-	false ->
-	    %% Just remove any wrapper. `erl_parse' nodes never contain
-	    %% abstract syntax tree nodes as subtrees.
-	    unwrap(Node);
-	true ->
+    case Node of
+	#tree{} ->
 	    case is_leaf(Node) of
 		true ->
 		    revert_root(Node);
@@ -7482,7 +7478,18 @@ revert(Node) ->
 		    %% parts, and revert the node itself.
 		    Node1 = update_tree(Node, Gs),
 		    revert_root(Node1)
-	    end
+	    end;
+	#wrapper{tree = Node1, attr = Attr} ->
+	    %% Just remove the wrapper. The wrapped `erl_parse' nodes never
+	    %% contain abstract syntax tree nodes as subtrees. Carry over
+	    %% the position information, unless it is a warning/error marker
+            case Node1 of
+                {error, _} -> Node1;
+                {warning, _} -> Node1;
+                _ -> setelement(2, Node1, Attr#attr.pos)
+            end;
+        _ ->
+            Node
     end.
 
 %% Note: The concept of "compatible root node" is not strictly defined.
@@ -7679,10 +7686,10 @@ revert_forms_1([T | Ts]) ->
 	    revert_forms_1(Ts);
 	_ ->
 	    T1 = revert(T),
-	    case is_tree(T1) of
-		true ->
+	    case T1 of
+		#tree{} ->
 		    throw({error, T1});
-		false ->
+		_ ->
 		    [T1 | revert_forms_1(Ts)]
 	    end
     end;
-- 
2.43.0

openSUSE Build Service is sponsored by