dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
515 stars 97 forks source link

"do {}" blocks should be allowed as a part of an expression #3316

Closed mikhail-turilin-dfinity closed 2 years ago

mikhail-turilin-dfinity commented 2 years ago

In the following example function "number2" doesn't compile and it's not clear why.

   public query func number1() : async Nat {
    let x = 40; let y = 2;
    x+y
  };

  public query func number2() : async Nat {
    let x = 40; let y = 2;
    x + y + do {
      let x = 1;
      let y = x + 1;
      x * y + x
    } + x + y
  };

  public query func number3() : async Nat {
    let x = 40; let y = 2;
    do {
      let x = 1;
      let y = x + 1;
      x * y + x
    }
  };
crusso commented 2 years ago

We should explain in the doc that nested do expressions require parens.

crusso commented 2 years ago

https://internetcomputer.org/docs/current/developer-docs/build/languages/motoko/basic-concepts#from-declarations-to-block-expressions might be a good place to add this (at the end)

crusso commented 2 years ago

Fixed in doc branch here https://github.com/dfinity/motoko/pull/3172/commits/5c99f088131338854d413cecbf072ba4479cb426 @mikhail-turilin-dfinity

crusso commented 2 years ago

(This will propagate to the web the next time the portal team does a sync)