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

Confusing message for out parameters for new users #3835

Closed
MikaelMayer opened this issue Apr 3, 2023 · 3 comments · Fixed by #4168
Closed

Confusing message for out parameters for new users #3835

MikaelMayer opened this issue Apr 3, 2023 · 3 comments · Fixed by #4168

Comments

@MikaelMayer
Copy link
Member

MikaelMayer commented Apr 3, 2023

We got several confused new Dafny users that, in the following program:

method Callee() returns (i: int) {
  i := 0;
}
method Caller() {
  Callee();
}

would not understand the error message

wrong number of method result arguments (got 0, expected 1)

because they are passing the correct number of arguments to the method.

What is confusing is actually

  • They skip the word "result"
  • In no other language I know is there such a thing of returning multiple values (not out parameters), so this is very novel.
  • We are calling these parameters which should be to the left of the method "result arguments", which is weird. Arguments are passed usually to the right of the method name inside parentheses. At best, result arguments should be prefixed with "out" like in C#. However, here they are not arguments.

Here are alternative messages that could help reduce the friction for new users

  • 1️⃣ The method returns 1 value(s) but is assigned to 0 variable(s). All return values must be assigned.
  • 2️⃣ Wrong number of assignment variables to store the result of the method (expected 1, got 0)
  • 3️⃣ The number of assignment variables is not the same as the number of return values (expected 1, got 0)
  • 4️⃣ Mismatch between returned values (1) and assignments (0)

Please add your alternatives and/or vote so that we can make a better error message

Update
Based on three votes, we choose

The method returns 1 value(s) but is assigned to 0 variable(s). All return values must be assigned.

@keyboardDrummer
Copy link
Member

The term "result parameter" is difficult to interpret for me. I would prefer "return value".

Option 1 seems great. Consider adding a sentence "All return values must be assigned"

@MikaelMayer
Copy link
Member Author

Good catch for "result parameter" instead of now "return values" in option 3. See, even I am biased towards the Dafny language, it's good that we have these discussions just to realized how awkward a dialect might seem.

I also added "All return values must be assigned" to option 1, which I think adds value.

@davidcok
Copy link
Collaborator

I vote for #1

keyboardDrummer pushed a commit that referenced this issue Jun 13, 2023
)

This PR fixes #3835
I added the corresponding test.

<small>By submitting this pull request, I confirm that my contribution
is made under the terms of the [MIT
license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
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

Successfully merging a pull request may close this issue.

3 participants