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

Binary patterns and Elixir.String.t #16

Closed
mbuhot opened this issue Jun 26, 2018 · 7 comments
Closed

Binary patterns and Elixir.String.t #16

mbuhot opened this issue Jun 26, 2018 · 7 comments
Milestone

Comments

@mbuhot
Copy link

mbuhot commented Jun 26, 2018

Hello, thanks for creating Gradualizer!
I tried it out on a simple module and ran into this error:

# foo.ex
defmodule Foo do
  @spec is_comment?(String.t()) :: boolean
  def is_comment?("#" <> _rest), do: true
  def is_comment?(_), do: false
end
iex(4)> :gradualizer.type_check_module(Foo)
The pattern <<"#",_rest@1/binary>> on line 3 doesn't have the type 'Elixir.String':t()
:nok

Looks like it hasn't resolved the type Elixir.String.t as a synonym for binary ?

@josefs
Copy link
Owner

josefs commented Jun 26, 2018

The gradualizer currently doesn't know anything about Elixir. But it would be really nice to support it! Patches are welcome.
@tim2CF do you have any thoughts on this?

@tim2CF
Copy link
Contributor

tim2CF commented Jun 27, 2018

Hello!
I'll take a look on this week :)

@gomoripeti
Copy link
Collaborator

hello, I think this warning is caused by Gradualizer not yet supporting binaries (and binary patterns). If you replace String.t() with binary() you will still get a similar warning.

@zuiderkwast
Copy link
Collaborator

Hi! I have added two commits for binaries/bitstrings (70a42c2 subtype relation and 37399e4 type checking bit expressions and patterns). Perhaps this helps a bit? It is not really well-tested yet...

@josefs josefs added this to the Beta release milestone Oct 5, 2018
@josefs
Copy link
Owner

josefs commented Oct 5, 2018

@mbuhot, I believe we've added the support needed for your program to go through Gradualizer. Can you confirm?

@mbuhot
Copy link
Author

mbuhot commented Oct 6, 2018

@josefs I still getting a type error, but now it is consistent whether the function is typed as String.t or binary.

iex(7)> :gradualizer.type_check_module(Foo)
The pattern "#" on line 0 doesn't have the type integer()
:nok

Looks like there is a comment in the tests (https://github.com/josefs/Gradualizer/blob/master/test/should_pass/bitstring.erl#L5-L9) indicating that binary patterns don't type check against binary type specs.

Feel free to close this issue if you'd rather track binary pattern support (independent of Elixir) separately.

@josefs
Copy link
Owner

josefs commented Oct 6, 2018

@mbuhot, thanks for your quick feedback! The error message that you get now is rather puzzling to me but we don't have anyone working on Elixir support so I'm afraid it won't be investigated any time soon. So I'll close this ticket then.

The comment that you pointed to turned out to be outdated and I've updated the test case to reflect that.

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

No branches or pull requests

5 participants