Teach erl_syntax:is_literal/1 to recognize utf8 binaries#10962
Open
bjorng wants to merge 1 commit intoerlang:masterfrom
Open
Teach erl_syntax:is_literal/1 to recognize utf8 binaries#10962bjorng wants to merge 1 commit intoerlang:masterfrom
erl_syntax:is_literal/1 to recognize utf8 binaries#10962bjorng wants to merge 1 commit intoerlang:masterfrom
Conversation
Contributor
CT Test Results 2 files 13 suites 3m 21s ⏱️ Results for commit 4a39245. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts
// Erlang/OTP Github Action Bot |
A literal binary encoded as UTF8 would not be recognized as
a literal by `erl_syntax:is_literal/1`:
1> Tree = fun(S) -> {ok,Toks,_} = erl_scan:string(S),
{ok,[Tree]} = erl_parse:parse_exprs(Toks),
Tree end.
#Fun<erl_eval.42.113135111>
2> erl_syntax:is_literal(Tree(~s'<<"abc">>.')).
true
3> erl_syntax:is_literal(Tree(~s'<<"abc"/utf8>>.')).
false
4> erl_syntax:is_literal(Tree(~s'~"abc".')).
false
This had consequences for `merl`. Consider the following module:
-module(merl_example).
-export([f/0]).
-include_lib("syntax_tools/include/merl.hrl").
f() ->
Mod = some_module,
Tree = ?Q([~"""
-module('@mod@').
"""]),
merl:print(Tree).
Since the triple-quoted binary is encoded in UTF8, which is not
recognized by `erl_syntax:is_literal/1` as a literal, the `merl` parse
transform will not do the expected substitution of `@Mod@`:
c(merl_example).
merl_example.erl:6:5: Warning: variable 'Mod' is unused
% 6| Mod = some_module,
% | ^
{ok,merl_example}
2> merl_example:f().
-module('@mod@').
ok
After updating `erl_syntax:is_literal/1` to recognize an UTF8-encoded
binary, this will work:
1> c(merl_example).
{ok,merl_example}
2> merl_example:f().
-module(some_module).
ok
333e2d2 to
4a39245
Compare
lucioleKi
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A literal binary encoded as UTF8 would not be recognized as a literal by
erl_syntax:is_literal/1:This had consequences for
merl. Consider the following module:Since the triple-quoted binary is encoded in UTF8, which is not recognized by
erl_syntax:is_literal/1as a literal, themerlparse transform will not do the expected substitution of@Mod@:After updating
erl_syntax:is_literal/1to recognize an UTF8-encoded binary, this will work: