Skip to content

Erroneous "typing violation" warning #13746

Closed
@marcandre

Description

@marcandre

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.0.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Elixir 1.17.2 (compiled with Erlang/OTP 25)

Operating system

Mac OS 14.5 (23F79)

Current behavior

The following code compiles with a false warning error:

    x = fn -> 42 end
    if is_atom(x), do: x.__live__()

We get:

    warning: expected a module (an atom) when invoking __live__/0 in expression:

        x.__live__()

    where "x" was given the type:

        # type: fun()
        # from: lib/basic_app_web/live/user_live/index.ex:9
        x = fn x -> x end

    hint: "var.field" (without parentheses) means "var" is a map() while "var.fun()" (with parentheses) means "var" is an atom()

    typing violation found at:
    │
 10 │     if is_atom(x), do: x.__live__()
    │                          ~
    │
    └─ lib/basic_app_web/live/user_live/index.ex:10:26: BasicAppWeb.UserLive.Index.mount/3

Clearly, this code should not error, as x.__live__() will be called only if x is an atom.

This is particularly problematic as our CI is currently set with --warnings-as-errors, and we get this error when calling Phoenix.LiveViewTest.render_component/3 in our tests. Is there a workaround?

Expected behavior

Expecting no warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions