File 4171-stdlib-Extend-erl_parse-abstract-to-handle-funs.patch of Package erlang

From 2b4301035e4a722451b3c6beefbf02cda5f86492 Mon Sep 17 00:00:00 2001
From: Hans Bolinder <hasse@erlang.org>
Date: Tue, 18 Feb 2020 16:00:50 +0100
Subject: [PATCH] stdlib: Extend erl_parse:abstract() to handle funs

---
 lib/stdlib/src/erl_parse.yrl       | 14 +++++++++++++-
 lib/stdlib/test/erl_scan_SUITE.erl | 11 ++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl
index 70bc65835f..eab8da4ab7 100644
--- a/lib/stdlib/src/erl_parse.yrl
+++ b/lib/stdlib/src/erl_parse.yrl
@@ -1462,7 +1462,19 @@ abstract(List, A, E) when is_list(List) ->
 abstract(Tuple, A, E) when is_tuple(Tuple) ->
     {tuple,A,abstract_tuple_list(tuple_to_list(Tuple), A, E)};
 abstract(Map, A, E) when is_map(Map) ->
-    {map,A,abstract_map_fields(maps:to_list(Map),A,E)}.
+    {map,A,abstract_map_fields(maps:to_list(Map),A,E)};
+abstract(Fun, A, E) when is_function(Fun) ->
+    case erlang:fun_info(Fun, type) of
+        {type, external} ->
+            Info = erlang:fun_info(Fun),
+            {module, M} = lists:keyfind(module, 1, Info),
+            {name, F} = lists:keyfind(name, 1, Info),
+            {arity, Arity} = lists:keyfind(arity, 1, Info),
+            {'fun', A, {function,
+                        abstract(M, A, E),
+                        abstract(F, A, E),
+                        abstract(Arity, A, E)}}
+    end.
 
 abstract_list([H|T], String, A, E) ->
     case is_integer(H) andalso H >= 0 andalso E(H) of
diff --git a/lib/stdlib/test/erl_scan_SUITE.erl b/lib/stdlib/test/erl_scan_SUITE.erl
index 4ae3301ca0..162e2a0a3d 100644
--- a/lib/stdlib/test/erl_scan_SUITE.erl
+++ b/lib/stdlib/test/erl_scan_SUITE.erl
@@ -1,7 +1,7 @@
 %%
 %% %CopyrightBegin%
 %%
-%% Copyright Ericsson AB 1998-2019. All Rights Reserved.
+%% Copyright Ericsson AB 1998-2020. All Rights Reserved.
 %%
 %% Licensed under the Apache License, Version 2.0 (the "License");
 %% you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
 	 init_per_group/2,end_per_group/2]).
 
 -export([error_1/1, error_2/1, iso88591/1, otp_7810/1, otp_10302/1,
-	 otp_10990/1, otp_10992/1, otp_11807/1]).
+	 otp_10990/1, otp_10992/1, otp_11807/1, otp_16480/1]).
 
 -import(lists, [nth/2,flatten/1]).
 -import(io_lib, [print/1]).
@@ -58,7 +58,7 @@ suite() ->
 
 all() -> 
     [{group, error}, iso88591, otp_7810, otp_10302, otp_10990, otp_10992,
-     otp_11807].
+     otp_11807, otp_16480].
 
 groups() -> 
     [{error, [], [error_1, error_2]}].
@@ -1197,6 +1197,11 @@ otp_11807(Config) when is_list(Config) ->
          (catch erl_parse:abstract("string", [{encoding,bad}])),
    ok.
 
+otp_16480(Config) when is_list(Config) ->
+    F = fun mod:func/19,
+    F = erl_parse:normalise(erl_parse_abstract(F)),
+    ok.
+
 test_string(String, ExpectedWithCol) ->
     {ok, ExpectedWithCol, _EndWithCol} = erl_scan_string(String, {1, 1}, []),
     Expected = [ begin
-- 
2.16.4

openSUSE Build Service is sponsored by