Why doesn't `<system>` work?

I did add <system> to my code, but it does not compile anyway. What did I do wrong?

.mops/base@0.10.4/src/ExperimentalCycles.mo:96.60-96.77: type error [M0096], expression of type
  <system>Nat -> Nat
cannot produce expected type
  Nat -> Nat
.mops/base@0.10.4/src/ExperimentalCycles.mo:124.43-124.57: type error [M0096], expression of type
  <system>Nat -> ()
cannot produce expected type
  Nat -> ()
import Cycles "mo:base/ExperimentalCycles";
import Int "mo:base/Int";
import Debug "mo:base/Debug";
import Nat "mo:base/Nat";

module {
    public func topUpCycles<system>(maxCycles: Nat): (accepted : Nat) {
        // Debug.print("maxCycles: " # debug_show(maxCycles) # " Proposed cycles: " # debug_show(Cycles.available()) # " balance: " # debug_show(Cycles.balance()));
        // let amount = Int.min(maxCycles, Int.max(0, Cycles.available() + Cycles.balance()));
        let amount = Int.min(maxCycles, Cycles.available()) - Cycles.balance();
        let amount2 = Int.max(amount, 0);
        // Debug.print("Accepting cycles: " # debug_show(amount2));
        Cycles.accept<system>(Int.abs(amount2));
    };

    public func addPart<system>(maxAmount: Nat) {
        let amount = Nat.min(Cycles.balance() / 2, maxAmount);
        ignore Cycles.accept(amount);
        // Debug.print("adding " # debug_show(amount) # " cycles");
        Cycles.add<system>(amount);
    };
}

Functions using need to be async mate

Like that

But why? Isn’t this async an extra slow-down?!

In the previous version of the compiler (before <system> appeared), async was not required. And that was OK.

Don’t think async is required.

It’s probably this line in addPart:

ignore Cycles.accept<system>(amount);

No, after I added this it still does not compile.

My guess is you are using Motoko 10 or below? But your Motoko plugin is expecting motoko 11?

cannot produce expected type
  Nat -> ()

This type is from Motoko 10

Probably so, indicated by the output mentioning base@0.10.4. I guess base@0.10.4 wouldn’t work with moc 0.11.0 and would result in different (earlier) errors at the imports already.

No, I use 11:

$ moc --version
Motoko compiler 0.11.0+ (source yh3wb1vx-vj8j4j32-k8gq4m8y-4cxlqinf)

Well actually looks like your code is not compiling, so that might be something else, nonetheless the update to Motoko 11 seems to have a brought a few bugs :thinking:

The following solved the problem:

$ mops update base
Package installed base = "0.11.0"
2 Likes