I'm trying to compile a module from forms, with included header files. First, if I have the module in a source file, everything works fine.
user.hrl
-record(user, {name :: string()}).
zed.erl
-module(zed).
-export([f/1]).
-include("user.hrl").
f(User) ->
User#user.name.
shell
1> compile:file(zed, [return]).
{ok,zed,[]}
2> rr("user.hrl").
[user]
3> zed:f(#user{name = "Zed"}).
"Zed"
If I try to compile the same module from forms, I get an undefined record error. Playing with {i, Dir}
and other options does not help.
shell
1> Forms = [{attribute,1,module,zed},
1> {attribute,1,export,[{f,1}]},
1> {attribute,1,include,"user.hrl"},
1> {function,1,f,1,
1> [{clause,1,
1> [{var,1,'User'}], [],
1> [{record_field,1,
1> {var,1,'User'},
1> user,
1> {atom,1,name}}]}]}].
....
2> compile:forms(Forms, [return]).
{error,[{".",[{1,erl_lint,{undefined_record,user}}]}],[]}
What am I doing wrong?