Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerant record construction #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mheiber
Copy link
Owner

@mheiber mheiber commented Jan 25, 2021

Update Dialyzer so that functions
that construct bad records are not
treated as no_returning.

Constructing a record in a way that
doesn't match the type signature is
never a runtime error.

By having Dialyzer reflect this behavior,
we can avoid false positives
and helps find real bugs.

For example, before this change, running
Dialyzer on the code below would produce
4 false positives before the user sees
a meaningful warnings. And any
genuine bugs after the bad record
construction were hidden:

-record(rec, {field :: float() }).

a() -> b().
b() -> c().
c() -> d().
d() ->
#rec{field = 3},
% ... more code here
ok.

sample.erl:6: Function a/0 has no local return
sample.erl:7: Function b/0 has no local return
sample.erl:8: Function c/0 has no local return
sample.erl:9: Function d/0 has no local return
sample.erl:9: Record construction
#rec{field :: 3} violates the declared type of field field ::
float()

With this change, only a single warning is shown
when there are no more discrepancies in d/0.

Update Dialyzer so that functions
that construct bad records are not
treated as `no_return`ing.

Constructing a record in a way that
doesn't match the type signature is
never a runtime error.

By having Dialyzer reflect this behavior,
we can avoid false positives
and helps find real bugs.

For example, before this change, running
Dialyzer on the code below would produce
4 false positives before the user sees
a meaningful warnings. And any
genuine bugs after the bad record
construction were hidden:

-record(rec, {field :: float() }).

a() -> b().
b() -> c().
c() -> d().
d() ->
    #rec{field = 3},
    % ... more code here
    ok.

sample.erl:6: Function a/0 has no local return
sample.erl:7: Function b/0 has no local return
sample.erl:8: Function c/0 has no local return
sample.erl:9: Function d/0 has no local return
sample.erl:9: Record construction
          #rec{field :: 3} violates the declared type of field field ::
          float()

With this change, only a single warning is shown
when there are no more discrepancies in d/0.
Update small_SUITE to reflect that
there are no more no_returns errors
caused by bad record constructions

And update typer_SUITE to make sure typer
still shows functions with bad constructions
as returning none()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant