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

Compiler allows reusing of the same argument name when defining a function #473

Closed
matteojug opened this issue Aug 16, 2024 · 2 comments
Closed
Assignees

Comments

@matteojug
Copy link
Contributor

matteojug commented Aug 16, 2024

When defining a function, the compiler allows reusing the same name for different args, while interpreting the clarity code raises an error.

Failing test:

#[test]
fn reuse_arg_name() {
    crosscheck_compare_only("(define-private (foo (a int) (a int)) a) (foo 1 2)")
}

results in:

assertion `left == right` failed: Compiled and interpreted results diverge! (define-private (foo (a int) (a int)) a) (foo 1 2)
compiled: Ok(Some(Int(2)))
interpreted: Err(Unchecked(NameAlreadyUsed("a")))
  left: Ok(Some(Int(2)))
 right: Err(Unchecked(NameAlreadyUsed("a")))
@obycode
Copy link
Collaborator

obycode commented Aug 26, 2024

Adding a note here that the interpreter catches this at runtime, not at deploy time, so for example if you just have:

(define-public (foo (a int) (a int)) (ok a))

This will deploy fine, but only when you call it will it report a runtime error:

error: Runtime Error: Runtime error while interpreting ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.contract-3: Unchecked(NameAlreadyUsed("a"))

@csgui csgui self-assigned this Sep 10, 2024
@saralab saralab assigned matteojug and unassigned csgui Sep 10, 2024
@matteojug matteojug moved this from Status: 🆕 New to Status: 💻 In Progress in Stacks Core Eng Sep 12, 2024
@matteojug matteojug moved this from Status: 💻 In Progress to Status: In Review in Stacks Core Eng Sep 12, 2024
@matteojug
Copy link
Contributor Author

Done in #510

@github-project-automation github-project-automation bot moved this from Status: In Review to Status: ✅ Done in Stacks Core Eng Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Status: ✅ Done
Development

No branches or pull requests

4 participants