File 5657-compiler-Binaries-are-acceptable-moduledoc-strings.patch of Package erlang

From d3bb51ecc66ac985adb732defcdb38b6f7c32552 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Backstr=C3=B6m?= <lukas@erlang.org>
Date: Tue, 24 Mar 2026 09:24:47 +0100
Subject: [PATCH] compiler: Binaries are acceptable moduledoc strings

closes #10901
---
 lib/compiler/src/beam_doc.erl                 |  2 +-
 lib/compiler/test/beam_doc_SUITE.erl          | 20 +++++++-
 .../test/beam_doc_SUITE_data/binary_doc.erl   | 47 +++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)
 create mode 100644 lib/compiler/test/beam_doc_SUITE_data/binary_doc.erl

diff --git a/lib/compiler/src/beam_doc.erl b/lib/compiler/src/beam_doc.erl
index a9a9d31abc..06311d6bb6 100644
--- a/lib/compiler/src/beam_doc.erl
+++ b/lib/compiler/src/beam_doc.erl
@@ -505,7 +505,7 @@ extract_moduledoc0({attribute, ModuleDocAnno, moduledoc, false}, State) ->
    extract_moduledoc0({attribute, ModuleDocAnno, moduledoc, hidden}, State);
 extract_moduledoc0({attribute, ModuleDocAnno, moduledoc, hidden}, State) ->
    State#docs{moduledoc = {ModuleDocAnno, create_module_doc(hidden)}};
-extract_moduledoc0({attribute, ModuleDocAnno, moduledoc, ModuleDoc}, State) when is_list(ModuleDoc) ->
+extract_moduledoc0({attribute, ModuleDocAnno, moduledoc, ModuleDoc}, State) when is_list(ModuleDoc); is_binary(ModuleDoc) ->
    Doc = unicode:characters_to_binary(string:trim(ModuleDoc)),
    State#docs{moduledoc = {set_file_anno(ModuleDocAnno, State), create_module_doc(Doc)}};
 extract_moduledoc0(_, State) ->
diff --git a/lib/compiler/test/beam_doc_SUITE.erl b/lib/compiler/test/beam_doc_SUITE.erl
index f347274efc..552e4ce1cc 100644
--- a/lib/compiler/test/beam_doc_SUITE.erl
+++ b/lib/compiler/test/beam_doc_SUITE.erl
@@ -1,6 +1,7 @@
 
 -module(beam_doc_SUITE).
--export([all/0, groups/0, init_per_group/2, end_per_group/2, singleton_moduledoc/1, singleton_doc/1,
+-export([all/0, groups/0, init_per_group/2, end_per_group/2,
+         singleton_moduledoc/1, singleton_doc/1, binary_doc/1,
          docmodule_with_doc_attributes/1, hide_moduledoc/1, docformat/1,
          singleton_docformat/1, singleton_meta/1, slogan/1,
          types_and_opaques/1, callback/1, hide_moduledoc2/1,
@@ -30,6 +31,7 @@ end_per_group(_, _Config) ->
 documentation_generation_tests() ->
     [singleton_moduledoc,
      singleton_doc,
+     binary_doc,
      docmodule_with_doc_attributes,
      hide_moduledoc,
      hide_moduledoc2,
@@ -74,6 +76,22 @@ singleton_doc(Conf) ->
            {{function, main,0},_, [<<"main()">>], Doc, _}]}} = code:get_doc(ModName),
     ok.
 
+binary_doc(Conf) ->
+    ModuleName = "binary_doc",
+    {ok, ModName} = default_compile_file(Conf, ModuleName),
+
+    ModuleDoc = #{<<"en">> => <<"This is a binary moduledoc docstring">>},
+    TypeDoc = #{<<"en">> => <<"This is a binary type docstring">>},
+    CallbackDoc = #{<<"en">> => <<"This is a binary callback docstring">>},
+    FooDoc = #{<<"en">> => <<"This is a binary function docstring">>},
+
+    {ok, {docs_v1, _,_, _, ModuleDoc, _,
+                [{{type,type,0},_,[<<"type()">>],TypeDoc, _},
+                 {{callback,callback,0},_,[<<"callback()">>], CallbackDoc, _},
+                 {{function,foo,0},_,[<<"foo()">>], FooDoc, _}]}}
+           = code:get_doc(ModName),
+    ok.
+
 docmodule_with_doc_attributes(Conf) ->
     ModuleName = "docmodule_with_doc_attributes",
     {ok, ModName} = default_compile_file(Conf, ModuleName),
diff --git a/lib/compiler/test/beam_doc_SUITE_data/binary_doc.erl b/lib/compiler/test/beam_doc_SUITE_data/binary_doc.erl
new file mode 100644
index 0000000000..1a996d0a65
--- /dev/null
+++ b/lib/compiler/test/beam_doc_SUITE_data/binary_doc.erl
@@ -0,0 +1,47 @@
+-module(binary_doc).
+
+-moduledoc ~"
+This is a binary moduledoc docstring
+".
+
+-export([foo/0]).
+
+-doc ~"
+This is a binary type docstring
+".
+-type type() :: ok.
+
+-doc ~"
+This is a binary callback docstring
+".
+-callback callback() -> type().
+
+-doc ~"
+This is a binary function docstring
+".
+-spec foo() -> type().
+foo() ->
+    ok.
+
+%%
+%% %CopyrightBegin%
+%%
+%% SPDX-License-Identifier: Apache-2.0
+%%
+%% Copyright Ericsson AB 2026. 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.
+%% You may obtain a copy of the License at
+%%
+%%     http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+
-- 
2.51.0

openSUSE Build Service is sponsored by