[erlang-questions] dialyzer error on fun2ms output

Peti Gömöri gomoripeti@REDACTED
Fri Oct 14 00:13:15 CEST 2016


Hi list,

I noticed that the below code snippet although compiles and works fine
results in a dialyzer error (on for example OTP 19.1)

```
-module(ms).
-export([t/0]).

-include_lib("stdlib/include/ms_transform.hrl").

t() ->
    MS = dbg:fun2ms(fun(All) -> message(All) end),
    erlang:trace_pattern({m, f, '_'}, MS).
```

and the error is

ms.erl:9: The call erlang:trace_pattern({'m', 'f',
'_'},MS::[{'$1',[],[{'message','$1'},...]},...]) breaks the contract
(MFA,MatchSpec) -> non_neg_integer() when MFA :: trace_pattern_mfa() |
'send' | 'receive', MatchSpec :: MatchSpecList::trace_match_spec() |
boolean() | 'restart' | 'pause'

The reason is that dbg:fun2ms generates the match-spec:
[{'$1',[],[{message,'$1'}]}]
But the type as seen in erlang.erl or erts_internal.erl only allows a list
or the wildcard atom '_' as the match-spec head.
-type trace_match_spec() :: [{[term()] | '_' ,[term()],[term()]}].

The match-spec grammar definition in
http://erlang.org/doc/apps/erts/match_spec.html clearly allows a match
variable as head but I understand it is impossible to express '$<number>'
as a proper erlang type.

I'm not sure if ms_transform should be modified to always generate
match-specs according to the type spec or rather the type-spec should be
adjusted to allow all legal match specifications (eg by adding atom() to
the match head type)


thanks
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161014/6ea5c4d6/attachment.htm>


More information about the erlang-questions mailing list