File 0151-Fixes-issue-9645.patch of Package erlang
From 5e0a2991e8284f0e085a5351fb3f89cd4f8eb970 Mon Sep 17 00:00:00 2001
From: Kai Lothar John <l.john@glvi.de>
Date: Sat, 29 Mar 2025 10:55:52 +0100
Subject: [PATCH 1/2] Fixes issue #9645
Invoking help about function in module in Erlang shell raised
exception in shell_docs:render_function/3.
The exception was due to a missing pattern match on the return value
of `beam_lib:chunks/2`.
Split the function in two, one handling errors from `find_path/1`; the
other handling the return value of `beam_lib:chunks/2`.
---
lib/stdlib/src/shell_docs.erl | 38 ++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/lib/stdlib/src/shell_docs.erl b/lib/stdlib/src/shell_docs.erl
index f8949c6a57..84c3e011f5 100644
--- a/lib/stdlib/src/shell_docs.erl
+++ b/lib/stdlib/src/shell_docs.erl
@@ -590,24 +590,26 @@ render_type(Module, D) ->
%% extract AST raw type specifications.
extract_type_specs(Module) ->
- maybe
- Path = find_path(Module),
- true ?= non_existing =/= Path,
- {ok, {_ModName,
- [{debug_info,
- {debug_info_v1,erl_abstract_code,
- {AST, _Opts}}}]}} ?= beam_lib:chunks(Path, [debug_info]),
-
- %% the mapping keys 'type', 'function', and 'callback' correspond
- %% to existing EEP-48 {**Kind**, Name, Arity} format, where Kind
- %% ranges over these values. This is needed to differentiate
- %% function, callback, and types when looking up their type specs
- Acc = #{type => #{}, 'function' => #{}, 'callback' => #{}},
- lists:foldl(fun filter_exported_types/2, Acc, AST)
- else
- false -> #{}; % when non_existing =/= Path,
- {error,beam_lib,{file_error,_,_}} -> #{} % from beam_lib:chunks/1
- end.
+ case find_path(Module) of
+ Path when is_list(Path); is_list(binary) ->
+ extract_type_specs1(Path);
+ _ ->
+ #{}
+ end.
+
+%% extract AST raw type specifications.
+extract_type_specs1(Path) ->
+ case beam_lib:chunks(Path, [debug_info]) of
+ {ok, {_ModName, [{debug_info, {debug_info_v1, erl_abstract_code, {[_|_] = AST, _Opts}}}]}} ->
+ %% the mapping keys 'type', 'function', and 'callback' correspond
+ %% to existing EEP-48 {**Kind**, Name, Arity} format, where Kind
+ %% ranges over these values. This is needed to differentiate
+ %% function, callback, and types when looking up their type specs
+ Acc = #{'type' => #{}, 'function' => #{}, 'callback' => #{}},
+ lists:foldl(fun filter_exported_types/2, Acc, AST);
+ _ ->
+ #{}
+ end.
-spec find_path(Mod :: module()) -> non_existing | file:filename_all().
find_path(Module) ->
--
2.43.0