Skip to content

Lazy loading of modules does not work when accessing native records. #11392

Description

@m-2k

Describe the bug
Lazy loading of modules does not work for native records.

An exception {badrecord,{Module,Name}} is generated when a Native Record from another module is declared in the code but that module has not yet been loaded.

To Reproduce

  1. write application with two modules:
-module(db).
-export_record([product]).

-record #product{id}.
-module(helper).
-compile(export_all).

y() -> #db:product{id=2232}.
  1. add a call helper:y() into application:start/2 or call it manually via the attached console:
$ rebar3 shell
Erlang/OTP 29 [erts-17.0.3] [source] [64-bit] [smp:18:18] [ds:18:18:10] [async-threads:1] [jit]
Eshell V17.0.3 (press Ctrl+G to abort, type help(). for help)
1> helper:y().
** exception error: {badrecord,{db,product}}
     in function  helper:y/0 (src/helper.erl:8)
2> code:load_file(db).
{module,db}
3> helper:y().
#db:product{id = 2232}

Expected behavior
When attempting to access a native record from another module, the target module will be preloaded and the Native Record is created without errors.

Affected versions

❯ cat .tool-versions                
erlang 29.0.3
rebar 3.27.0

Additional context
rebar3 and erlc exhibit the same behavior

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions