Return types and discrepancies between estdlib and OTP
I discovered some discrepancies with some of the returns from estdlib with OTP.
OTP gen_* modules export a per-behaviour start_ret() type that are functional equivalents, but AtomVM specs use {ok, pid()} | {error, Reason::term()} for the return. The OTP modules have an exported type of start_ret/0:
-type start_ret() :: {ok, pid()} | {error, Reason::term()}.
These can be used in other modules function specs (as example): gen_statem:start_ret().
Dialyzer doesn't seem to mind, but tools like gradualizer will complain about the difference.
I also think it might be good if we consider exporting some of the common types from a few of the eavmlib modules that are likely to be used by downstream drivers and libraries. This would be types like:
-
gpio:pin() -
i2c:i2c() -
i2c:params() -
spi:spi() -
spi:bus_config() -
spi:device_config()
I think this could help improve clarity and be beneficial when using code analysis tools.