bad match question

Matthias Lang matthias@REDACTED
Tue Jun 7 17:21:11 CEST 2005

Charles Blair writes:
 > i'm curious why the bad match here isn't caught until runtime:
 > -module(test).
 > -compile([export_all]).
 > start() ->
 >   Test = [a, b, c],
 >   Test = [1, 2, 3].

The above code _must_ generate a badmatch at runtime, such are
Erlang's semantics. A sufficiently smart compiler could choose to
generate the same code as it would have generated for

   start() ->
     exit({badmatch, [1, 2, 3]}).

And yes, it would be nice if the compiler generated a warning for your
code, but it doesn't. The dialyzer probably does (I haven't tried).


More information about the erlang-questions mailing list