File 0821-Revert-syntax-tools-Fix-reverting-discarding-pos-cha.patch of Package erlang

From 5690c7dfe28b1fb0982e55c8fead642a7ce55612 Mon Sep 17 00:00:00 2001
From: Richard Carlsson <carlsson.richard@gmail.com>
Date: Mon, 30 Dec 2024 19:09:21 +0100
Subject: [PATCH 1/4] Revert "syntax tools: Fix reverting discarding pos
 changes"

This partially reverts commit 5bbee0e2fa4f549035765ab5ad4ce033d8f8605a,
keeping the added test case. The commit caused unnecessary recursive
traversal and rebuilding of a whole abstract format term T when T was
contained in a wrapper structure. Such traversal is precisely what the
use of the wrapper was meant to avoid.
---
 lib/syntax_tools/src/erl_syntax.erl | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/lib/syntax_tools/src/erl_syntax.erl b/lib/syntax_tools/src/erl_syntax.erl
index e1ec49ab82..e47d513934 100644
--- a/lib/syntax_tools/src/erl_syntax.erl
+++ b/lib/syntax_tools/src/erl_syntax.erl
@@ -830,18 +830,14 @@ _See also: _`copy_pos/2`, `get_pos/1`.
 
 set_pos(Node, Pos) ->
     case Node of
-        #tree{attr = Attr} ->
-            Node#tree{attr = Attr#attr{pos = Pos}};
-        #wrapper{attr = Attr, tree = {error, {_, Module, Reason}}} ->
-            Node#wrapper{attr = Attr#attr{pos = Pos}, tree = {error, {Pos, Module, Reason}}};
-        #wrapper{attr = Attr, tree = {warning, {_, Module, Reason}}} ->
-            Node#wrapper{attr = Attr#attr{pos = Pos}, tree = {warning, {Pos, Module, Reason}}};
-        #wrapper{attr = Attr, tree = Tree} ->
-            Node#wrapper{attr = Attr#attr{pos = Pos}, tree = setelement(2, Tree, Pos)};
-        _ ->
-            %% We then assume we have an `erl_parse' node, and create a
-            %% wrapper around it to make things more uniform.
-            set_pos(wrap(Node), Pos)
+	#tree{attr = Attr} ->
+	    Node#tree{attr = Attr#attr{pos = Pos}};
+	#wrapper{attr = Attr} ->
+	    Node#wrapper{attr = Attr#attr{pos = Pos}};
+	_ ->
+	    %% We then assume we have an `erl_parse' node, and create a
+	    %% wrapper around it to make things more uniform.
+	    set_pos(wrap(Node), Pos)
     end.
 
 
@@ -7466,7 +7462,13 @@ _See also: _[//stdlib/erl_parse](`m:erl_parse`), `revert_forms/1`.
 -spec revert(syntaxTree()) -> syntaxTree().
 
 revert(Node) ->
-    case is_leaf(Node) of
+    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 is_leaf(Node) of
 		true ->
 		    revert_root(Node);
 		false ->
@@ -7480,6 +7482,7 @@ revert(Node) ->
 		    %% parts, and revert the node itself.
 		    Node1 = update_tree(Node, Gs),
 		    revert_root(Node1)
+	    end
     end.
 
 %% Note: The concept of "compatible root node" is not strictly defined.
-- 
2.43.0

openSUSE Build Service is sponsored by