Gradualizer icon indicating copy to clipboard operation
Gradualizer copied to clipboard

exhaustiveness issue alert for wrong parameter

Open berbiche opened this issue 3 years ago • 2 comments

I found an issue related to the message printed when an exhaustive check finds non-exhaustive patterns.

The following test case incorrectly reports that the second parameter is not exhaustive while the issue lies in the first parameter:

-module(error3).

-export([my_function/2]).

-record(my_record, { something :: non_neg_integer() }).

-spec my_function(#my_record{} | undefined, non_neg_integer()) -> #my_record{}.
my_function(Record = #my_record{}, Number) ->
    Record#my_record{something = Number}.

As we can see, the undefined value is not handled by any function body but this is what Gradualizer reports:

/gradualizer/error3.erl: Nonexhaustive patterns on line 8 at column 1
Example values which are not covered:
	0

If the fix in #411 is applied, this is the issue reported:

/gradualizer/error3.erl: Nonexhaustive patterns on line 8 at column 1
Example values which are not covered:
	undefined

cc: @zuiderkwast it seems you were right in https://github.com/josefs/Gradualizer/issues/339#issuecomment-895786061.

berbiche avatar May 16 '22 18:05 berbiche

OK, good findings! Why did you close #411?

zuiderkwast avatar May 16 '22 21:05 zuiderkwast

OK, good findings! Why did you close #411?

I closed the PR after re-reading the comment before it multiple times. https://github.com/josefs/Gradualizer/blob/3b96c4568e29a51173f6427954120d9055543511/src/typechecker.erl#L3477-L3490 Also I had not found a reproducible issue that could show why the fix was necessary so I abandoned the effort.

But with this issue, I found at least one case that shows why the refinement check should be done against the refined arguments.

berbiche avatar May 17 '22 15:05 berbiche