another bounds example - catched by normal compile but not by dialyzer
Tobias Lindahl
Tobias.Lindahl@REDACTED
Tue Jun 27 09:51:31 CEST 2006
Roger Larsson wrote:
> Furter experimentation:
> * Static checking of array bounds is a simpler problem than handling dynamic
> lists.
> So, lets try the same kind of errors with tuples.
>
> Normal compile detects these simple cases. But dialyzer
> return some strange messages.
> At least the dialyzer output is hard to decipher...
>
> -module(bounds).
> -export([detect/0, wrong_match/0]).
>
> detect() -> element(4, {1, 2, 3}).
> wrong_match() -> {_, _, _, _} = {1, 2, 3}.
>
>
>>erl
>
> 1> c(bounds).
> ./bounds.erl:4: Warning: this expression would cause a 'badarg' exception at
> run-time
> ./bounds.erl:5: Warning: this clause cannot match because of different
> types/sizes
> {ok,bounds}
>
>
>>dialyzer (from source)
>
> {bounds,detect,0}: Function has no local return
> {bounds,wrong_match,0}: Function has no local return
Strangely enough the problem is that the error is too easy to find ;-)
The BEAM compiler finds the problem and simply removes it, leaving only
the exception. Since Dialyzer first compiles the code to an internal
format and then perform the analysis on this code, it only finds that
there is no non-exception return for the functions and warns about this.
This is indeed a problem, but not a very severe one since you get the
warning from the compiler.
Tobias
>
> /RogerL
More information about the erlang-questions
mailing list