Skip to main content

L1336 - Illegal Native Record Field Default

Error

-module(main).
-record(#point {x = self(), y}).
%% ^ error: illegal default value for field x in native record point

Explanation

The error occurs when the default value of a native record (EEP-79) field is not a compile-time constant.

Native record field defaults are restricted to literal/constant expressions (integers, floats, atoms, strings, and lists/tuples/maps/binaries built from such values). Run-time expressions such as self() or a function call are not allowed. To fix the error, use a constant default, or initialize the field at each creation site instead.