propcheck icon indicating copy to clipboard operation
propcheck copied to clipboard

Strange behavior when adding code after forall

Open pallix opened this issue 1 year ago • 2 comments

I encountered this strange behaviour today. Given the following code:


    property "some property" do
      forall i <- integer() do
        IO.inspect(i, label: "i")
        test_some_property()
      end
    end

    property "some other property" do
      forall i <- integer() do
        IO.inspect(i, label: "ii")
        test_some_property()
      end
      test_some_other_property()
    end

    defp test_some_property do
      true
    end

    defp test_some_other_property do
      true
    end

only the code block with the label: i with be executed. Obviously it makes little sense to have test_some_other_property() after the forall but given my code was more complex than the example it took me a while to find the problem.

Is that the expected behaviour? Would it make sense to give a warning or error?

pallix avatar Aug 29 '22 18:08 pallix

Hi @pallix , nice catch, this is similar to #112. We should warn about that in the documentation. Since propcheck relies heavily on macros and code generation, it could be difficult to identify that situation (i.e. the Elixir compiler does not detect that situation, so we would have to do that by ourselves).

Happy to receive a pull request!

alfert avatar Aug 30 '22 07:08 alfert

In #112 both code blocks are executed but here only the one external to the forall. Am I correct?

pallix avatar Aug 30 '22 10:08 pallix