aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.2k stars 3.67k forks source link

[Bug][move-compiler-v2] tuple assignment to var message is confusing #12669

Open brmataptos opened 8 months ago

brmataptos commented 8 months ago

🐛 Bug

PR 12223 fixes the error message in third_party/move/move-compiler-v2/tests/checking/typing/assign_wrong_arity.exp but it is still confusing.

The relevant code is:

5:        let x;
6:        x = ();
7:        x = (0, 1, 2);

The new error output is:

Diagnostics:
error: the left-hand side has 0 items but the right-hand side provided 3
  ┌─ tests/checking/typing/assign_wrong_arity.move:7:9
  │
7 │         x = (0, 1, 2);
  │         ^

which is better than before, but it is still confusing because the real problem is assigning a tuple to a local var at all.

That test output is also failing to error on the previous statement which assigns () to x, since those errors show up later in the compiler, in code generation. The message suggests that the type analysis is giving x a fixed type of Tuple(0), whichi is kind of strange.

Anyway, this particular error should be easy enough to fix in type analysis by changing the error message if the target seems to be of type Tuple(0).

vineethk commented 7 months ago

Another test case to add for this issue (taken from third_party/move/move-compiler-v2/tests/bytecode-generator/wildcard1.move from this PR: https://github.com/aptos-labs/aptos-core/pull/12818):

module 0xc0ffee::m {
    fun tup(): (u64, u64) {
        (0, 0)
    }

    public fun bar() {
        let _ = tup();
    }
}

Here, v1 points to the return type of tup(), which can be helpful (although the wording used by v1 is probably what we want to use).