Property generators make Dialyzer complain, ideas how to make it happy?

Hello all,
I got a lot of functions like these in a hobby project of mine:

  @spec optional_alphanum(pos_integer) :: %StreamData{}
  def optional_alphanum(size) when size > 0 do
    gen all str <- string([?A..?Z, ?0..?9], min_length: 0, max_length: size) do
      String.pad_trailing(str, size, " ")
    end
  end

To which Dialyzer (through dialyxir) always complains: Function optional_alphanum/1 has no local return. I also tried appending | no_return() to the return type, and it did not help.

Any clues? I am aware that ExUnitProperties.gen is a macro but cannot decipher what I have to do to make Dialyzer happy in this case.

If you don’t like opinions that say to change your libraries you can skip now.

Take a look into using PropCheck for the generators instead of StreamData. They have more control and are better at shrinking. It might also solve your dialyzer issue.

1 Like

Well, I invested a lot in this personal project and I have like 800+ lines of code using ExUnitProperties and StreamData. But your idea is interesting and I can try it on a much smaller scale. :+1:

I’ve seen that too, I think it needs to be fixed inside StreamData.

@whatyouhide Really sorry for direct mention. :icon_redface: As the author, do you happen to know how can this be alleviated?

@adkron could you expand on these two points?

@dimitarvp can you open an issue in stream_data?

A bit offtopic but it happens from time to time that dialyzer catches problems that are external to my application (like wrong specs in a dependency), in these cases there is a way to silence specific warnings (s. Erlang -- dialyzer ).

As a temporary measure you can add something like that to your module so that this function does not trigger warnings:

@dialyzer {:nowarn_function, optional_alphanum: 1}

1 Like

Done: https://github.com/whatyouhide/stream_data/issues/130

Thanks for chiming in!

Fair point. But since this is a personal project, I won’t insist on 100% @spec coverage or put Dialyzer as a pre-commit hook. For the time being it’s fine if my generators aren’t specced in a way that Dialyzer likes.

1 Like

I was trying to dig back through old code and find an example where I had issues with shrinking, but it looks like @kethley already put in an issue with one of the problems. https://github.com/whatyouhide/stream_data/issues/107

The other features of type generation that I have wanted, and found readily in PropCheck and or Proper, are targeted properties and controlled shrinking.

The other, IMO, significant gap in StreamData is stateful property-based testing. I hope to one day see that in StreamData, but for right now I put my eggs into PropCheck due to the years of work and effort that it is leveraging in Proper.

If you use stateful testing there’s definitely no alternative, so nothing to say there :slight_smile:

I’ll look into what it would take to get those into stream_data :slight_smile:

4 Likes

That would be great to see. I always like to see multiple tools with multiple approaches. I think they help us, as a community, to learn and grow.

1 Like