cadence icon indicating copy to clipboard operation
cadence copied to clipboard

BUG: Using `result` as a variable name causes a checker error

Open joshuahannan opened this issue 4 years ago • 1 comments
trafficstars

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

joshuahannan avatar Apr 06 '21 18:04 joshuahannan

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 avatar Apr 06 '21 18:04 turbolent