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

Wrongfully saying that it has a shared call #4583

Open
vporton opened this issue Jun 28, 2024 · 6 comments
Open

Wrongfully saying that it has a shared call #4583

vporton opened this issue Jun 28, 2024 · 6 comments

Comments

@vporton
Copy link

vporton commented Jun 28, 2024

In this commit run make deploy-stress-test.

/home/porton/Projects/nacdb/src/example/partition/main.mo:103.16-103.106: type error [M0187], send capability required, but not available
  (cannot call a `shared` function from a `composite query` function; only calls to `query` and `composite query` functions are allowed)

But the function Nac.scanLimitOuter does not call shared functions (even indirectly), only query ones.

So, I suppose, this error message is wrong.

@vporton
Copy link
Author

vporton commented Jun 29, 2024

Minimal reproducible example:

actor Partition {
    public composite query func scanLimitOuterComposite() : async ()
    {
        await* N.outer();
    };

    module N {
        public type Test = actor {
            inner: query() -> async ();
        };

        public func outer(): async* () {
            let part: Test = actor("aaaaa-aa");
            await part.inner();
        };
    };
}
$ moc main.mo 
main.mo:4.16-4.25: type error [M0187], send capability required, but not available
  (cannot call a `shared` function from a `composite query` function; only calls to `query` and `composite query` functions are allowed)

You see that it does only a query call and no shared function calls. The compiler's message is wrong.

@crusso
Copy link
Contributor

crusso commented Jul 1, 2024

Thanks for the report.

Thanks, yes the message is in accurate, but I would still expect there to be an error here. Like all type systems, the type system is being conservative here. Although in your case it doesn't call a shared function, in general some other version of outer() (of the same type) could call a shared function, so we reject the call-site within scanLimitOuterComposite.

@vporton
Copy link
Author

vporton commented Jul 1, 2024

in general some other version of outer()

There cannot be some other version of outer: it is called a fixed function from a fixed module, there is only one such function.

@vporton
Copy link
Author

vporton commented Jul 14, 2024

in general some other version of outer()

There cannot be some other version of outer: it is called a fixed function from a fixed module, there is only one such function.

Do you convince your error?

@vporton
Copy link
Author

vporton commented Aug 1, 2024

I simplified the code to the following, it still produces the same error:

actor Partition {
    public composite query func scanLimitOuterComposite() : async ()
    {
        await* N.outer();
    };

    module N {
        public func outer(): async* () {};
    };
}

@ggreif
Copy link
Contributor

ggreif commented Aug 2, 2024

I narrowed it down to

actor Partition {
    public query func scanLimitOuterComposite() : async ()
    {
        await* async* {};
    };
}

The error is

Error [M0038] in file Main.mo:3:8 misplaced await
Error [M0037] in file Main.mo:3:15 misplaced async expression; a query cannot contain an async expression
While not perfectly precise, I can kind-of understand why this is not allowed. Any async* expression can send messages, and this is not allowed because a query is not allowed to send.

Your example has composite query, so dropping that in, we get this error:

Error [M0037] in file Main.mo:3:15 misplaced async expression; a composite query cannot contain an async expression
Error [M0087] in file Main.mo:3:15 ill-scoped await: expected async type from current scope $scanLimitOuterComposite, found async type from other scope $bogus scope $scanLimitOuterComposite is Main.mo:3.5-5.6
Warning [] in file Main.mo:2:4 start of scope $scanLimitOuterComposite mentioned in error at Main.mo:4.9-4.25
Warning [] in file Main.mo:4:4 end of scope $scanLimitOuterComposite mentioned in error at Main.mo:4.9-4.25

This is really cryptic.

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

3 participants