-
-
Notifications
You must be signed in to change notification settings - Fork 775
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
Add qualifiers for type variables in generated Erlang typespecs #3221
Comments
@lpil isn't it better to use a bound instead of term directly? Let's say this was the function (from the OTP PR mentioned above): -spec foo(atom()) -> {ok, X} | {error, X} Then instead of -spec foo(atom()) -> {ok, term()} | {error, term()} I think it's better to have -spec foo(atom()) -> {ok, X} | {error, X} when X :: term() In this way, the typespec correctly signals that the type should be the same in the two branches? |
Are you sure? I just double checked this locally with the example from erlang/otp#6915: -module(foo).
-export([foo/1]).
-spec foo(atom()) -> {ok, X} | {error, X}.
foo(X) ->
{ok, X}. ❯ erlc foo.erl
foo.erl:5:27: Warning: type variable 'X' is only used once (is unbound)
% 5| -spec foo(atom()) -> {ok, X} | {error, X}.
% | ^ While -module(foo).
-export([foo/1]).
-spec foo(atom()) -> {ok, X} | {error, X} when X :: term().
foo(X) ->
{ok, X}. does not emit an warning (this is on OTP 26.2.5). |
Huh. OK I don't understand what's happening here. It says "once" but it's clearly used twice. Is this a bug in erlc? |
Yeah the message is a bit confusing, I think it's more about the (is unbound) part. Apparently for the compiler -spec foo(atom()) -> {ok, X} | {error, X} when X :: term(). |
I've opened an issue with Erlang/OTP to find out if this warning is emitted incorrectly, or if the text is misleading. |
@lpil I may have confused you with the following comment OTP 26.2.5 also emits a warning without the type guard, it's because of the added type guard that no warning is emitted. I posted a clarification on the issue as well. |
Thank you. This is all very confusing to me. I guess we add seemingly redundant qualifiers to everything! |
Yeah it is, I guess we're all spoiled by the errors in Gleam ;) |
term()
in generated Erlang
term()
in generated Erlang
Looks like I'm totally wrong about how they work. erlang/otp#8533 |
I saw the conversation :) So for now we only add |
I think so? It's still incorrect though unfortunately. |
Yeah, it's the best we can do for now. I was busy with playing around with gleam-lang/erlang#45 but I can pick this one up, wanted to get familiar with the Rust codebase anyways :) |
@lpil any idea how I can trigger the issue in a isolated test? I tried this but It makes me think: isn't that what should have been generated in the example in this issue? |
PR is submitted! |
Starting from OTP 26 erlang/otp#6915, warnings are emitted for unbound type variables, for example:
We need to replace this unbound type variable with
term()
so that no warning is emitted.originally reported in gleam-lang/erlang#46
The text was updated successfully, but these errors were encountered: