Skip to content

URI.parse has incorrect type spec for path #11424

@breunigs

Description

@breunigs

Environment

Erlang/OTP 24 [erts-12.1.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.13.0-rc.1 (0974e90) (compiled with Erlang/OTP 22

Current behavior

iex(2)> URI.parse("http://")
%URI{
  authority: "",
  fragment: nil,
  host: "",
  path: nil, # it's nil
  port: 80,
  query: nil,
  scheme: "http",
  userinfo: nil
}

however:

iex(6)> t URI  
@opaque authority()

@type t() :: %URI{
        authority: authority(),
        fragment: nil | binary(),
        host: nil | binary(),
        path: binary(), # it can't be nil
        port: nil | :inet.port_number(),
        query: nil | binary(),
        scheme: nil | binary(),
        userinfo: nil | binary()
      }

In my 1.12 code I had a nil check for path, since it can be nil. When updating, Dialyzer complained that this check can never succeed -- and according to the type spec that's true:

dummy.ex:2:guard_fail
The guard clause:

when _ :: binary() === nil

can never succeed.

However, removing it of course will cause issues down the line.

Expected behavior

I don't really have a desired behaviour. The angle I'm coming from is that URI.parse was only mentioned as a soft-deprecation, so I expected that my existing code keeps working, including type-checks. So simply updating the changelog would be fine by me. I guess removing the type-spec from URI.parse also works.

related: #11363

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