What are the details of "non-static" restrictions in library or module

When compiling the motoko code, an error is reported:

 make test
make -C test
[INFO] Installing 2 packages
[INFO] Installation complete.
.vessel/.bin/0.6.5/moc --package base .vessel/base/927119e172964f4038ebc7018f9cc1b688544bfa/src --package matchers .vessel/matchers/v1.2.0/src -wasi-system-api -o Test.wasm Test.mo && wasmtime Test.wasm
../src/engine/fast_portable/mod.mo:28.42-28.62: type error [M0014], non-static expression in library or module
../src/engine/fast_portable/mod.mo:30.17-30.37: type error [M0014], non-static expression in library or module
../src/engine/fast_portable/mod.mo:31.9-31.37: type error [M0014], non-static expression in library or module
make[1]: *** [default] Error 1
make: *** [test] Error 2
mod.mo source code
import Alphabet "../../alphabet";

module {
    public type FastPortable = {
        encode_table: [Nat8];
    };

    // public let DEFAULT_ENGINE = 
    public let INVALID_VALUE: Nat8 = 255;

    public class FastPortableConfig() {
        var encode_padding: Bool = true;
        var decode_allow_trailing_bits: Bool = false;

        public func with_encode_padding(padding: Bool) {
            encode_padding := padding;
        };

        public func with_decode_allow_trailing_bits(allow: Bool) {
            decode_allow_trailing_bits := allow;
        };

        public func encode_padding() : Bool {
            encode_padding
        };
    };

    public let PAD: FastPortableConfig = FastPortableConfig();
    public let NO_PAD: FastPortableConfig = do {
        let f = FastPortableConfig();
        f.with_encode_padding(false);
        f
    };
};

It seems that there is a restriction in motoko. Object classes cannot be constructed in the module because they are non-static. Is there any relevant document to explain this restriction? I can’t find it here:

1 Like

I believe this is the section you are looking for: Language quick reference :: Internet Computer

2 Likes