dimitarvp

dimitarvp

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.

Most Liked

whatyouhide

whatyouhide

Elixir Core Team

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:

adkron

adkron

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.

yurko

yurko

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. dialyzer — dialyzer v5.4 ).

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}

dimitarvp

dimitarvp

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.

adkron

adkron

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.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement