[erlang-bugs] Dialyzer does not check record update types

Nicolas Dudebout nicolas.dudebout@REDACTED
Sun Nov 23 12:56:20 CET 2014


Dialyzer checks the type of record elements when creating them but not when
updating them. Pasted below is a minimal working example.

Nicolas




-module(test).

-export([ baz/1, quux/2 ]).

-type bar()    :: atom().
-type notbar() :: string().

-record(foo, { bar :: bar() }).


% CORRECT: Dialyzer generates a warning
% test.erl:13: Invalid type specification for function test:baz/1. The
success typing is (atom()) -> #foo{bar::atom()}
-spec baz(notbar()) -> #foo{}.

baz(NotBar) ->
  #foo{ bar = NotBar }.

% INCORECT: Dialyzer does not say anything
-spec quux(#foo{}, notbar()) -> #foo{}.

quux(Foo, NotBar) ->
  Foo#foo{ bar = NotBar }.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20141123/e71bc56c/attachment.htm>


More information about the erlang-bugs mailing list