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

Fails to recognize that pos_integer() * pos_integer() will always return pos_integer() #182

Open
skwerlman opened this issue Apr 20, 2024 · 0 comments

Comments

@skwerlman
Copy link

I have the following code:

{dx, dy} = Matrex.size(matrix)
elems = dx * dy

Matrex.size/1 has a spec of size(matrex()) :: {index(), index()} where index() is an alias for pos_integer().

When I use elems later on in code that expects an index(), gradient incorrectly complains that it has type integer():

lib/noise/printer.ex: Matrex.reshape()/3 call arguments on line 11 don't match the function type:
(list(matrex()), index(), index() -> matrex())
(list(element()), index(), index() -> matrex())
(matrex(), index(), index() -> matrex())
(Range.t(), index(), index() -> matrex())
(Enumerable.t(), index(), index() -> matrex())
Inferred argument types:
%{required(:__struct__) => Matrex, required(:data) => binary()}, 1, integer()

for now im working around this with this function:

@compile {:inline,
          hack_to_make_gradient_realize_that_pos_int_times_pos_int_is_always_pos_int: 2}
@spec hack_to_make_gradient_realize_that_pos_int_times_pos_int_is_always_pos_int(
        pos_integer(),
        pos_integer()
      ) :: pos_integer()
defp hack_to_make_gradient_realize_that_pos_int_times_pos_int_is_always_pos_int(a, b), do: a * b
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

1 participant