Skip to content

Bad type violation detection in 1.19 #14887

@Sgiath

Description

@Sgiath

Elixir and Erlang/OTP versions

Erlang/OTP 28 [erts-16.1.1] [source] [64-bit] [smp:32:32] [ds:32:32:10] [async-threads:1] [jit:ns]

Elixir 1.19.1 (compiled with Erlang/OTP 28)

Operating system

x86_64-linux, Linux 6.17.4-xanmod1, NixOS, 25.11 (Xantusia), 25.11.20251031.2fb006b

Current behavior

This is basically my code:

case error do
  %{message: message} when is_binary(message) ->
    Logger.error("Error happened: #{message}")

  _otherwise ->
    Logger.error("Weird error happened: #{inspect(error)}")
end

And compiler finds type violation on line 3 - message has type term() but expected a type that implements the String.Chars protocol. But there is a guard is_binary/1 on this case branch so the type is clear. Not sure if it is a bug or the type system is not able to work with guard in this place but it probably should not be reported as type violation.

Expected behavior

No type violation is reported.

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