credo icon indicating copy to clipboard operation
credo copied to clipboard

Slash inside macro

Open hissssst opened this issue 2 years ago • 4 comments

Environment

1.6.4-ref.deletion.8140e31+uncommittedchanges

What were you trying to do?

x = 1
p = path(x / x)

where path is a macro

Expected outcome

No warning

Actual outcome

┃ [W] ↗ Operation will always return 1.

hissssst avatar May 14 '22 20:05 hissssst

Why do you think this should not raise an issue?

Your code x / x is (on the surface) always resulting in the same result which Credo points out, unless I am missunderstanding you (note that you did not provide any explanation in this issue).

rrrene avatar May 15 '22 09:05 rrrene

Hi, that's a good question.

Here path is a macro. It accepts an AST and generated a code from it. So it does not necessary use this AST in a way Elixir would use it. For example, my project pathex uses it for notation for Access-like lenses

hissssst avatar May 15 '22 21:05 hissssst

Actually, you can't make any assumptions about code which is passed into a macro as an argument. Sometimes this AST gets modified, and sometimes not.

hissssst avatar May 15 '22 21:05 hissssst

You are right. So we will habe to find a way to statically derermine whether or not something is a function or a macro 👍

rrrene avatar May 16 '22 04:05 rrrene

Closing this for age. As it never came up again, we can assume that there are not too many people encountering this.

If it becomes an issue again, we can refer to this issue 👍

rrrene avatar Dec 17 '23 07:12 rrrene