ignatov/intellij-erlang

object() function unresolved in the ets:fun2ms context

brigadier opened this issue · 2 comments

-include_lib("stdlib/include/ms_transform.hrl").
test() ->
	ets:fun2ms(fun(X) -> element(3, object()) end).

Intellij highlights object() as an undefined function. Actually it is a pseudofunction which is uderstood by the ms parse transform where it is converted to '$_'.
I think it is not possible to make syntax check work for every parse transform around, but might be some builtin ones worth it?

Hi, thanks for the report; as I'm right, that object() should be treated as a function at the top level, not like ms_transform:object?

it's a preudofunction which is used by the parse transformation, in compile time, so in runtime it does not exist. Yes, it's on the top level and it can be used only in the ets:fun2ms context and only if the module is compiled with ms_transform, such as -include_lib("stdlib/include/ms_transform.hrl").. Though I don't think it makes sense to check for the transform as it can be applied to the module in different ways. ets:fun2ms context is enough.

ets:fun2ms(fun({a,b,c}) -> object() end). %% - this gets transformed in compile time
[{{a,b,c},[],['$_']}] %% - this is what exist is in the compiled module