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

Module with "use Tesla" causes runtime error in Gradualizer #168

Open
japhib opened this issue May 5, 2023 · 1 comment
Open

Module with "use Tesla" causes runtime error in Gradualizer #168

japhib opened this issue May 5, 2023 · 1 comment
Labels
bug Something isn't working gradualizer-issue Needs addressing in Gradualizer

Comments

@japhib
Copy link
Contributor

japhib commented May 5, 2023

The Tesla library is a common HTTP client for Elixir. Part of the setup for using Tesla involves declaring a module that looks like this:

defmodule MyHTTPClient do
  use Tesla
  # define middlewares & configs
end

The use Tesla line invokes a macro that generates a sizable amount of code for this module. When that code is typechecked via mix gradient, it results in a runtime error like the following:

Typechecking files...

** (FunctionClauseError) no function clause matching in :gradualizer_lib.pick_value/2

    The following arguments were given to :gradualizer_lib.pick_value/2:

        # 1
        {:type, 0, :any, []}

        # 2
        {:env, ... [edited for brevity]

    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:160: :gradualizer_lib.pick_value/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:186: :gradualizer_lib."-pick_value/2-lc$^0/1-0-"/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:186: :gradualizer_lib."-pick_value/2-lc$^0/1-0-"/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:186: :gradualizer_lib.pick_value/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:196: :gradualizer_lib."-pick_value/2-lc$^2/1-2-"/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:197: :gradualizer_lib."-pick_value/2-lc$^2/1-2-"/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:197: :gradualizer_lib.pick_value/2
    (gradualizer) use_tesla/deps/gradualizer/src/gradualizer_lib.erl:154: :gradualizer_lib."-pick_values/2-lc$^0/1-0-"/2

The same error occurs when doing mix gradient lib/use_tesla.ex, i.e. invoking only the single file rather than the entire Mix project.

I've attempted to reproduce the issue on pure Elixir code (i.e. not macros) using Gradient's decompilation facilities in Gradient.Debug, but so far no luck. This definitely seems like an issue in Gradualizer rather than Gradient, but I'm still working on reproducing it with pure Erlang code.

I've created a PR that adds this case to Gradient as a (failing) unit test: #167

@erszcz erszcz added bug Something isn't working gradualizer-issue Needs addressing in Gradualizer labels May 8, 2023
@erszcz
Copy link
Member

erszcz commented May 8, 2023

Hi, @japhib!

Thanks for the report. It's another one in a row about gradualizer.pick_value/2 together with #169 and josefs/Gradualizer#530. We'll take a look into it, as this function ought to be guarded from getting spuriuos, non-normalised types such as this. I have a hunch it's connected with the support for intersection types aka overloaded functions aka functions with multiple clause specs - josefs/Gradualizer#461. We'll look into it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gradualizer-issue Needs addressing in Gradualizer
Projects
None yet
Development

No branches or pull requests

2 participants