Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert erl_anno:anno() to integer() at transform #4

Merged
merged 2 commits into from
Sep 20, 2023

Conversation

dw-kihara
Copy link
Contributor

The implementation of treating erl_anno:anno() in #3 has the following problems. (I'm very sorry.)

  • logi_location:unsafe_new/5 accepts line_or_anno() :: line() | erl_anno:anno() where erl_anno:anno() is opaque
    • when actual values like {10, 12} are placed after transform, dialyzer raises an error that says no compatible types
  • logi_transform:logi_location_expr/1 makes malformed abstract format values like {integer, {10, 12}, {10, 12}}
    • the third element of the tuple must be integer

This PR addresses these problems by converting erl_anno:anno() to integer() in the logi_transform process.
In addition, this fixes unintended pettern match in v0.0.12-compatible transform when Data is [].

@@ -111,7 +111,7 @@ transform_call(logi, Severity0, {_, _, _, Args} = Call, Loc = #location{line_or_
[Logger, {string, _, _} = Fmt] ->
Opts = {cons, LineOrAnno, {tuple, LineOrAnno, [{atom, LineOrAnno, logger}, Logger]}, {nil, LineOrAnno}},
logi_call_expr(Severity, Fmt, {nil, LineOrAnno}, Opts, Loc);
[Logger, {string, _, _} = Fmt, {nil, LineOrAnno} = Data] ->
[Logger, {string, _, _} = Fmt, {nil, _} = Data] ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When anno contains column, LineOrAnno that is bound at #location{line_or_anno = LineOrAnno} will not match here.

@@ -136,7 +136,7 @@ logi_location_expr(Loc = #location{line_or_anno = LineOrAnno}) ->
{atom, LineOrAnno, Loc#location.application},
{atom, LineOrAnno, Loc#location.module},
{atom, LineOrAnno, Loc#location.function},
{integer, LineOrAnno, LineOrAnno}
{integer, LineOrAnno, logi_transform_utils:line_or_anno_to_line(LineOrAnno)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When anno contains column, this made malformed abstract format values like {integer, {10, 12}, {10, 12}} wherer the third element must be an integer.

Copy link
Owner

@sile sile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks again 🙏

@sile sile merged commit 81737bb into sile:master Sep 20, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants