josefs / Gradualizer

A Gradual type system for Erlang
MIT License
613 stars 35 forks source link

Gradualizer can't tell that `m` and `f` don't exist in `erlang:apply(m, f, [some, args])` #561

Open erszcz opened 8 months ago

erszcz commented 8 months ago

Reported by @aleklisi on erlanger.slack.com. Here's how to reproduce.

Create a new library:

r3 new lib name=mylib

Within it create the following module:

$ cd mylib
$ cat src/z.erl
-module(z).

f() ->
    erlang:apply(m, f, [1,2,3]).

Add Gradualizer as a Rebar3 plugin and run:

rebar3 gradualizer

Compare with:

rebar3 xref

The latter returns info that m and f don't exist, but Gradualizer doesn't.

zuiderkwast commented 8 months ago

I don't think we have any magic handling of apply and I'm not sure a type checker should do that. It's rather something for other tools, like xref. Type wise, apply is just a function that takes some atoms and a list. The type module() is just an alias of atom().

erszcz commented 8 months ago

@zuiderkwast In general I agree, but I wanted to create a ticket to have a discussion around it, since this was raised by a colleague and I think it's worth considering. Given xref detects this, I don't think Gradualizer has to duplicate the functionality, but better have it documented that it's a deliberate choice and not just an omission.