E4036#
Cannot create values of the read-only type.
Erroneous Example#
In lib/lib.mbt, we declare a struct R with a private field __private:
pub(all) struct R {
x : Int
priv __private : Int
}
pub fn R::new(x : Int) -> R {
{ x, __private: 42 }
}
In main/main.mbt, we try to create a value of type R:
pub fn make() -> @lib.R {
{ x: 1, __private: 42 }
}
This gives the following error on line 1:
Cannot create values of struct type @lib.R because it contains private field(s).
Suggestion#
Construct the value using the public constructor:
pub fn make() -> @lib.R {
@lib.R::new(1)
}