[erlang-questions] [erlang-bugs] Inconsistent and incomprehensible handling of variables in spec's by compiler

Magnus Henoch magnus.henoch@REDACTED
Fri Feb 17 12:49:09 CET 2012


There is a big difference between this:

> -spec set_var(PrefixExp, Val, State) -> State.

and this:

> -spec set_var(PrefixExp::any(), Val::any(), State::any()) -> State::any().

The argument and return value type specifications are either Type
or Name::Type, so the first declaration says that the arguments
are of _types_ PrefixExp, Val and State, while the second declaration
says that all three arguments are of type any().  (As far as I know,
argument names are ignored by the compiler and dialyzer, and only
used by edoc.)  Specifying a singleton variable as the _type_ of an
argument is most likely not what the programmer meant, since it
doesn't add any information, so to me it makes sense to have the
compiler reject it.

That specification could be written like this:

-spec set_var(PrefixExp::any(), Val::any(), State::X) -> NewState::X.

which specifies that State and NewState must have the same type, no
matter which one.

Hope this helps,
-- 
Magnus Henoch
Erlang Solutions Ltd
http://www.erlang-solutions.com/




More information about the erlang-questions mailing list