elixir-tools / spitfire

Error tolerant parser for Elixir
https://www.elixir-tools.dev
MIT License
75 stars 7 forks source link

fix: typespec for Spitfire.Env #43

Closed mhanberg closed 5 months ago

mhanberg commented 5 months ago

Fixes #42

cc @zachdaniel - try this branch out and let me know if it works for you, then I'll merge and publish a patch.

zachdaniel commented 5 months ago

It doesn't appear to work for me.

lib/code/common.ex:200:pattern_match
The pattern can never match the type.

Pattern:
{:ok, _env}

Type:

  :error
  | %{:attrs => [any()], :functions => _, :macros => _, :variables => [any()], _ => _}

________________________________________________________________________________
lib/code/common.ex:221:unused_fun
Function use_alias/2 will never be called.
________________________________________________________________________________
lib/code/common.ex:594:pattern_match
The pattern can never match the type.

Pattern:
{:ok, _env}

Type:

  :error
  | %{:attrs => [any()], :functions => _, :macros => _, :variables => [any()], _ => _}

________________________________________________________________________________
done (warnings were emitted)
Halting VM with exit status 2
zachdaniel commented 5 months ago

wait, hang on, sorry, I tested main not this branch 🤦

zachdaniel commented 5 months ago

Ah, okay so I do still have an error, but the error is essentially on my end. The basic issue is that this env is technically safe to pass to expand_alias, but dialyzer still complains 😆 so I will do something like struct!(Macro.Env, spitfire_cursor_env)

zachdaniel commented 5 months ago

Yep, looks good to me 👍 The type is accurately reflecting the return, and struct(Macro.Env, spitfire_cursor_env) satisfies everything else 👍