stacks-network / stacks-network/stacks-core
[clarity] `var-get` of non existing data var returns `none` instead of throwing
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 3.1k
- Forks
- 762
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 76
Description
According to the docs, a var-get of a not-yet-existing var should throw an error; instead, it seems to be returning none:
clarity-repl v2.8.0
Enter "::help" for usage hints.
Connected to a transient in-memory database.
>> ::advance_chain_tip 1
1 blocks simulated, new height: 1
>> (define-data-var data int 1)
(define-public (foo (block uint)) (ok (at-block (unwrap-panic (get-block-info? id-header-hash block)) (var-get data))))
→ .ST000000000000000000002AMW42H.contract-0 contract successfully stored. Use (contract-call? ...) for invoking the public functions:
>> ::advance_chain_tip 1
1 blocks simulated, new height: 2
>> (contract-call? .contract-0 foo u1)
(ok 1)
>> (contract-call? .contract-0 foo u0)
(ok none)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior in clarity-repl using the documented var-get and at-block example from the issue, comparing a not-yet-existing variable with the existing-variable case. Trace the var-get execution path to determine why the missing value returns none; done means the documented missing-variable behavior is restored and covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- blockchain
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100