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

Type related issue #43

Open
OvermindDL1 opened this issue Oct 31, 2019 · 3 comments
Open

Type related issue #43

OvermindDL1 opened this issue Oct 31, 2019 · 3 comments

Comments

@OvermindDL1
Copy link

Nothing big, just noticing a potential couple bugs as I was running a new BEAM typer (it's a negative ML typer, not a weak positive typer like Dialyzer, Gradualizer, would make for an awesome addition into Dialyxir so I don't have to publish and keep up Gradualixir ^.^) over one of my projects and erlex had a couple things pop up that aren't entirely, though some are it's fault:

_build/test/lib/erlex/ebin/Elixir.Erlex.beam: The variable _byte@1 on line 269 is expected to have type integer() but it has type term()
_build/test/lib/erlex/ebin/Elixir.Erlex.beam: The pattern [61, 58, 61] on line 0 does not have type:
infix :: 'Elixir.String':t()
_build/test/lib/erlex/ebin/Elixir.Erlex.beam: The pattern [112, 97, 116, 116, 101, 114, 110, 32 | _rest@1] on line 0 does not have type:
pattern :: 'Elixir.String':t()

_build/test/lib/erlex/ebin/parser.beam: The pattern {ok, [{atom, _, Symbol}], _} on line 74 doesn't have the type {error,
           ErrorInfo :: error_info(),
           non_neg_integer() | {line(), column()}} |
          {ok,
           Tokens :: tokens(),
           non_neg_integer() | {line(), column()}}

And the lexer.erl file is fine.

In essence it's saying that:

  • The lib/erlex.ex file line 269 the byte in the expression of <<byte::8>> is supposed to have type integer, but it can potentially be any type, and thus can potentially fail, however that's because Elixir's Enum.into/3 isn't typespec'd properly, so that's entirely Elixir's fault.

  • The lib/erlex.ex file on (not actually line 0) https://github.com/asummers/erlex/blob/master/lib/erlex.ex#L73 it has the line def pretty_print_infix('=:='), do: "===" but it's typespec'd as @spec pretty_print_infix(infix :: String.t()) :: String.t() and Elixir's String.t() type is typespec'd as https://github.com/elixir-lang/elixir/blob/v1.9.2/lib/elixir/lib/string.ex#L213 :

    @type t :: binary

    And thus the character list is not a binary, hence it's failing (isn't dialyzer itself catching this one?!).

  • Same thing again on line https://github.com/asummers/erlex/blob/master/lib/erlex.ex#L96 with def pretty_print_pattern('pattern ' ++ rest) do when it's typespec'd as @spec pretty_print_pattern(pattern :: String.t()) :: String.t() binaries.

  • As for the parser file, no clue where it is complaining about, but it's missing a failure case and the success case is too tightly bound.

This was mostly just for fun, and the fact erlex only has 4 issues reported unlike the 4000 that most other libraries have. ^.^;

@asummers
Copy link
Owner

asummers commented Nov 7, 2019

That's actually showing a bug in Gradualixir (I think?). Pretty much everywhere I'm listing a String.t() in the typespecs as the input type for pretty_print_X should be a charlist() but it's not telling us that. Looking at my typespecs more closely, they have some really deep issues I need to address, but the type checks on your end are not telling us about them.

@OvermindDL1
Copy link
Author

OvermindDL1 commented Nov 7, 2019

It's still heavily in dev, though thus far what it detects has seemed pretty accurate, it just tends to crash or give excess errors about what it doesn't (like maps barely have support so far). I think it lets the typespec mostly override a function similar to dialyzer but I'm unsure yet, barely playing with it so far. However this library is small yet still complicated enough that it makes a great test bed for my experiments. :-)

@christhekeele
Copy link

Just an FYI @OvermindDL1 that this project now lives here, feel free to re-open this issue over there if it's still a thing.

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

3 participants