Record field matching problem under debugger

Wojtek Surowka wojteksurowka@REDACTED
Sun Jan 2 22:00:49 CET 2022


I have noticed that some functionality does not work for me if I run my
Erlang system under debugger. After investigation I constructed a
minimal example to see the problem. Is it expected or is it a bug? I
use Erlang/OTP 24.

The problem can be seen with the following module:

-module(testrec).
-export([test/0]).

-record(test, {field1, field2}).

func1(Field) when Field =:= #test.field1 -> ok.
func2(#test.field1) -> ok.

test() ->
    io:format("1: ~p~n", [func1(#test.field1)]),
    io:format("2: ~p~n", [func2(#test.field1)]).

If I compile this and run test(), I am getting two ok's printed as
expected. But if I start debugger first with debugger:start() and
select the module for debugging with ii(testrec) the function func2
does not work:

6> testrec:test().
1: ok
** exception error: no function clause matching testrec:func2(2)
(testrec.erl, line 7)
     in function  testrec:test/0 (testrec.erl, line 11)

Thanks,
Wojtek


More information about the erlang-questions mailing list