sztosz

sztosz

defmodule A do
  def x() do
    Meeseeks.parse("<div id=main><p>Hello, Meeseeks!</p></div>")
  end
end

This gives me this error:

The call:
Meeseeks.parse(<<_::336>>)

will never return since it differs in arguments with
positions 1 from the success typing arguments:

(
  [
    binary()
    | {:comment, binary()}
    | {:pi, binary()}
    | {:pi | binary(), binary() | [{_, _}], binary() | [any()]}
    | {:doctype, binary(), binary(), binary()}
  ]
  | {:comment, binary()}
  | {:pi, binary()}
  | {:pi | binary(), binary() | [{binary(), binary()}], binary() | [any()]}
  | {:doctype, binary(), binary(), binary()}
)

When the specs for Meeseeks.parse is @spec parse(Parser.source()) :: Document.t() | {:error, Error.t()} with Parser.source() being @type source :: String.t() | TupleTree.t() and then TupleTree.t() being

  @type comment :: {:comment, String.t()}
  @type doctype :: {:doctype, String.t(), String.t(), String.t()}
  @type element :: {String.t(), [{String.t(), String.t()}], [node_t]}
  @type processing_instruction ::
          {:pi, String.t()}
          | {:pi, String.t(), [{String.t(), String.t()}]}
          | {:pi, String.t(), String.t()}
  @type text :: String.t()
  @type node_t :: comment | doctype | element | processing_instruction | text
  @type t :: node_t | [node_t]

Dialyxir and Dialyzer helped ma lot, but I don’t understand what’s wrong with those specs, or is it bug with tools rather.

If source :: String.t() | TupleTree.t() or source :: binary() | TupleTree.t() then call Meeseeks.parse(<<_::336>>) where <<_::336>> is binary should satisfy those specs. Right?

Beside, even when dialyxir/dialyzer says [...] will never return since [...] actually when run always returns and simply works OK.

Showing Posts 1 to 10

jeremyjh

jeremyjh

It looks like Dialyzer is finding the success type of the arg as list(Parser.source()) | Parser.source(), rather than the defined spec which is just Parser.source(). You could try fixing the spec in your local deps to and mix deps.compile meeseeks to try that out.

sztosz

sztosz OP

I really am not sure how to fix them, any pointers? :slight_smile:

jeremyjh

jeremyjh

What I’m suggesting is just change above spec to what appears to be the success typing:

@spec parse(list(Parser.source()) | Parser.source()) :: Document.t() | {:error, Error.t()}
jeremyjh

jeremyjh

Actually that is a problem but probably not YOUR problem. Your problem appears to be that binary is not accepted unless its in a list, so you’d change your call to Meeseeks.parse(["<div id=main><p>Hello, Meeseeks!</p></div>"]). I’m not sure why it would work and not generate a compatible success typing, its an issue in that library though.

sztosz

sztosz OP

Changing it into list does not work sadly :slight_smile:

I am not sure why dialyxir thinks that success typings is binary in a list etc `[binary() | … ] that is what I mainly try to understand.

jeremyjh

jeremyjh

Its due to a discontinuity in that spec versus the implementation of that function. What happens if you just remove the @spec from parse ?

sztosz

sztosz OP

I think dialyzer does not recompile its spec internally after commenting specs in meeseks, because errors are the same. I’ll try with fresh environment and simple project later this week, but can’t do it now, too much work :wink:

jeremyjh

jeremyjh

Did you run mix deps.compile meeseeks ? Dependencies are not recompiled automatically.

sztosz

sztosz OP

I did mix deps.compile after changing and it did recompiled meeseeks.

mischov

mischov

I’m pretty sure that list in the success typing there is because of @type t :: node_t | [node_t] in the TupleTree.t(), which should list every node type as contents of a list, but also every node type singularly.

However, it’s very interesting that
a) while the list of node_t properly contains binaries (representing text nodes), binary() isn’t included as a single node outside of the list as it properly should
b) a top level binary() isn’t provided since it should be included because of String.t() | TupleTree.().

Edit: This does highlight a logical problem when it comes to parsing, but I don’t think it should affect Dialyzer.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews