Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: local async function with non-async expression body are not reject as they (probably) should be. #4861

Open
crusso opened this issue Jan 21, 2025 · 1 comment

Comments

@crusso
Copy link
Contributor

crusso commented Jan 21, 2025

Looks like we have a bug in the type checker that is allowing these examples:

actor {
  func f() : async () {loop ()}; // legal
  func g() : async () = async {loop ()}; // legal
  func h() : async () = loop (); //should be illegal, body not an async expression
  public shared func go() : async () {
    let _ = f : () -> async ();
    let _ = g : () -> async ();
    let _ = h : () -> async ()
  }
}

https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=1246906498

However, even if we syntactically reject h(), can we still construct bad functions using generics or even just subtyping? Eg. something like:

func make_h<T>() : () -> T { func () : T = loop() };

let h = make_h<async()>();
@crusso
Copy link
Contributor Author

crusso commented Jan 21, 2025

Actually, we are probably ok but underlying type assigned to h doesn't look like an async function (missing scope parameter etc) so we can't use it to send a message and awaits will be ill-scoped.

import Timer "mo:base/Timer";

actor {

  func f() : async () {loop ()}; // legal

  func g() : async () = async {loop ()}; // legal

  func h() : async () = loop (); // body not an async expression


  let idf = Timer.setTimer<system>(#seconds 0, f);
  
  let idg = Timer.setTimer<system>(#seconds 0, g);

  let idh = Timer.setTimer<system>(#seconds 0, h); // rejected

  public shared func go() : async () {
    let _ = f : () -> async ();
    let _ = g : () -> async ();
    let _ = h : () -> async ()
  };


}

https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=3774773533

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant