Skip to content

Incompatible Type warning for compatible types (is_number, is_integer, is_float) #12505

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

Closed
novaugust opened this issue Mar 31, 2023 · 1 comment

Comments

@novaugust
Copy link
Contributor

novaugust commented Mar 31, 2023

Elixir and Erlang/OTP versions

Erlang/OTP 25 [erts-13.1.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]
Elixir 1.14.2 (compiled with Erlang/OTP 25)

Operating system

macos

Current behavior

Compiling this snippet raises a type warning:

defmodule Foo do
  def bar(token, number) when is_number(number) do
    case token do
      token when is_float(number) -> token
      token when is_integer(number) -> token
    end
  end
end
warning: incompatible types integer() !~ float() warning: incompatible types:
integer() !~ float()

in expression:

# test.exs:4
is_float(number)

where "number" was given the type integer() | float() in:

# test.exs:2
is_number(number)

where "number" was given the type float() in:

# test.exs:4
is_float(number)

Conflict found at
test.exs:4: Foo.bar/1

Expected behavior

notably this code correctly doesn't warn, which is the expected behaviour for the block above as well

defmodule Foo do
  def bar(number) when is_number(number) do
    case number do
      number when is_float(number) -> :float
      number when is_integer(number) -> :integer
    end
  end
end
@josevalim
Copy link
Member

Moved to #10485.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants