ignatov / intellij-erlang

Erlang IDE
https://www.jetbrains.com/help/idea/2018.2/getting-started-with-erlang.html
Other
735 stars 120 forks source link

Request: Macro expansion detected #532

Open bryanhughes opened 9 years ago

bryanhughes commented 9 years ago

Currently, if an variable is used in a macro, but no where else in the code block, it is marked as an unused variable. Would be nice if either 1) it is able to expand the macro or 2) we can disable the warning like you can do when using other languages like Java.

Here is some example code:

-define(THINGS_IDX, <<"TI.">>).
-define(THINGS_LINKED_INDEXNAME,  <<?THINGS_IDX/binary, APIKey/binary>>).

get_thingtypes_count(APIKey) ->
    gomachine_linkedindex:get_count(?THINGTYPES_LINKED_INDEXNAME).

Currently, APIKey in the function is marked as an unused variable resulting in the module never being able to become green.

kvakvs commented 8 years ago

This requires macro expansion pass before source is parsed.

I have similar problem. Code in Erlang/OTP source tests which looks like this:

?line P2 = spawn(timer, sleep, [1]),

where ?line macro is a legal sequence of tokens but is an illegal expression which also makes the source line where ?line is used an illegal expression, but they compile without errors when macro is expanded.

-define(line, io:format("something"),).

note the trailing comma.