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: Using result as a variable name causes a checker error #774

Closed
joshuahannan opened this issue Apr 6, 2021 · 1 comment · Fixed by #3589
Closed

BUG: Using result as a variable name causes a checker error #774

joshuahannan opened this issue Apr 6, 2021 · 1 comment · Fixed by #3589
Assignees
Labels
Documentation Improvements or additions to documentation Feedback Good First Issue Good for newcomers Improvement

Comments

@joshuahannan
Copy link
Member

Problem

The checker doesn't allow using the name result as a variable name,

Steps to Reproduce

Use this script:

pub fun main(): Int {
  let result = 1

  return result
}

See the error:

error: cannot redeclare result: `result` is already declared

Acceptance Criteria

I'm not sure if this is intentional or not. it might have something to do with the result of the script being checked in a post condition or something. Even if it is intentional, the error message should probably be improved to make it more clear

@turbolent
Copy link
Member

result is the special variable that can be used in post-conditions to refer to the value that is returned from the function, see https://docs.onflow.org/cadence/language/functions/#function-preconditions-and-postconditions.

Currently it is always declared in a function, even if there is no post-condition using it (analyzing this would require traversing all code of the function, which is expensive).

Agreed, it would be nice to at least improve the error message, because it is not obvious where this error comes from.

@turbolent turbolent added Documentation Improvements or additions to documentation Improvement and removed T-Bug 🐞 Bug Something isn't working labels Jan 21, 2022
@turbolent turbolent added the Good First Issue Good for newcomers label Sep 25, 2024
@turbolent turbolent mentioned this issue Sep 25, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation Feedback Good First Issue Good for newcomers Improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants