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

Nominal types: an edge case not accepted by dialyzer #9200

Open
ilya-klyuchnikov opened this issue Dec 16, 2024 · 1 comment
Open

Nominal types: an edge case not accepted by dialyzer #9200

ilya-klyuchnikov opened this issue Dec 16, 2024 · 1 comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM

Comments

@ilya-klyuchnikov
Copy link
Contributor

Describe the bug
Code is OK according to the rules (compatibility, type-checking) of nominal types, but is rejected by dialyzer.

To Reproduce

(This code has little sense, it's a minimal repro)

-module(n3).

-export([swap_r/1]).
-nominal t1() :: t2().
-nominal t2() :: integer().
-record(r, {t :: t1()}).

-spec swap_r(#r{}) -> #r{t :: t2()}.
swap_r(#r{t = T}) ->
  #r{t = T}.
dialyzer n3.erl
dialyzer: Analysis failed with error:
n3.erl:10:2: Illegal declaration of #r{t}

Expected behavior
According to the documentation and EEP, t1() and t2() are compatible nominal types, so using a refined record type #r{t :: t2()} should be fine.

Affected versions
Master

Additional context

Swapping definitions of t1() and t2() makes the error disappear:

-module(n4).

-export([swap_r/1]).

-nominal t1() :: integer().
-nominal t2() :: t1().

-record(r, {t :: t1()}).

-spec swap_r(#r{}) -> #r{t :: t2()}.
swap_r(#r{t = T}) ->
  #r{t = T}.
dialyzer n4.erl
(NO ERRORS)
@ilya-klyuchnikov ilya-klyuchnikov added the bug Issue is reported as a bug label Dec 16, 2024
@jhogberg
Copy link
Contributor

Thanks for your report! We'll have it fixed in the same branch as for #9199

@IngelaAndin IngelaAndin added the team:VM Assigned to OTP team VM label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

3 participants