8000 Dialyzer considering return type none() if type definition is violated with OTP-28 · Issue #9911 · erlang/otp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Dialyzer considering return type none() if type definition is violated with OTP-28 #9911
Open
@alexandrejbr

Description

@alexandrejbr

Describe the bug
I'm not sure this is a bug, but I am observing that in some circumstances calling a function with the wrong type makes dialyzer consider the return type is none(), so jumps to the conclusion that using the wrong type will lead to an exception.

To Reproduce
To reproduce you can use this example:

-type option() ::
        {'tracefun', term()} |
        {'context', list()}.

-spec start(term(), term()) -> {ok, term()} | error.
start(_StartType, _StartArgs) ->
    x_eval([{context, []},
            {tracefun, fun() -> ok end},
            {not_in_the_type_example, anything} %% Not in the type declaration 
           ]). 

-spec x_eval(Options) ->
          Result when
      Options :: [option()],
      State :: term(),
      Result :: {'ok', State} | error.

x_eval(_Options) ->
    {ok,ok}.

Which will give the following warning:

src/exercises_app.erl
Line 25 Column 2: Invalid type specification for function exercises_app:start/2. The success typing is (_,_) -> none() but the spec is (term(),term()) -> {'ok',term()} | 'error'
Line 26 Column 1: Function start/2 has no local return

Other situation where I saw this was when calling the function erl_tar:extract/2 passing cwd being a binary instead of a string.

For instance:

ok = erl_tar:extract({binary, Filename}, [compressed, {cwd, <<"">>}]).

Expected behavior
I would expect that either no warning is shown or that the message points to the type that is being violated instead of considering that the return type will be none() which is incorrect in the cases I have analysed.

Affected versions
OTP-28.0 and all the release candidates.

Additional context
Even if this is not a bug I would argue that this kind of error is not helpful. It was quite hard to figure out what was causing the warning.

Metadata

Metadata

Assignees

Labels

enhancementstalledwaiting for input by the Erlang/OTP teamteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0