Skip to content

map(of: ...) throws a protocol error #15

@michaelstalker

Description

@michaelstalker

I used the following example from the README, and got a protocol error:

ptest options: map(of: { atom, string}, min: 3, max: 7) do
  # This code results in a protocol error
end

Here's the error:

     ** (Protocol.UndefinedError) protocol Enumerable not implemented for {%Pollution.State{child_types: [], derived: [], distribution: nil, extra: %{delegate: %Pollution.State{child_types: [%Pollution.State{child_types: [], derived: [], distribution: nil, extra: nil, filters: %{}, last_child: nil, last_value: nil, max: 126, min: 33, must_have: [], type: Pollution.Generator.Int}], derived: [], distribution: nil, extra: nil, filters: %{}, last_child: nil, last_value: nil, max: 255, min: 0, must_have: [[]], type: Pollution.Generator.List}}, filters: %{}, last_child: nil, last_value: nil, max: 255, min: 0, must_have: [], type: Pollution.Generator.Atom}, %Pollution.State{child_types: [], derived: [], distribution: nil, extra: %{char_range: 0..55215}, filters: %{}, last_child: nil, last_value: nil, max: 300, min: 0, must_have: ["", " "], type: Pollution.Generator.String}}. This protocol is implemented for: Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream, StreamData
     code: ptest options: map(of: {atom, string}, min: 3, max: 7) do
     stacktrace:
       (elixir) /private/var/folders/8r/4czm10kj7095tkqm60s51n3h0000gp/T/elixir-build.20171012122108.21433/elixir-1.5.2/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
       (elixir) /private/var/folders/8r/4czm10kj7095tkqm60s51n3h0000gp/T/elixir-build.20171012122108.21433/elixir-1.5.2/lib/elixir/lib/enum.ex:116: Enumerable.reduce/3
       (elixir) lib/enum.ex:1847: Enum.map/2
       (pollution) lib/pollution/generators/map.ex:131: Pollution.Generator.Map.add_element_types_to_state/2
       (pollution) lib/pollution/generators/map.ex:24: Pollution.Generator.Map.create/1
       test/seo_metadata_service/datastore_test.exs:19: (test)

Removing the of: ... part makes the code work:

ptest options: map(min: 3, max: 7) do
  # This works great :)
end

I tried this with Elixir 1.4.0 and 1.5.2. Here's some Erlang/OTP information I get when I run elixir -v:

Erlang/OTP 20 [erts-9.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions