cfg_bind() binds a term argument's internal handle, so cfg_bind("x", parse_term("2")) binds x = 9

Open
#369 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
67/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r, rust
Domain
api, backend

Research direction

Start at the R cfg_bind() wrapper described in the issue and trace its .Call() into the Rust binding implementation. Check how the wrapper handles rssn_term values and vectors of length greater than one; use the examples in the issue to verify the behavior. Done means invalid inputs are rejected or terms bind to their evaluated values, with tests covering the reported cases.

Written by the indexing model from the issue text.

Description

area/api-bindings help wanted kind/wrong-result severity/3-major

cfg_bind() accepts an rssn_term and silently binds the symbol to the term's internal integer handle instead of its value, so cfg_bind("x", parse_term("2")) binds x = 9 (the handle), not x = 2.

library(rssn)
s <- rssn_session()
t <- parse_term("2", s)
unclass(t)                                    # 9  (the term handle)
cfg <- rssn_config() |> cfg_numeric(1e-12) |> cfg_bind("x", t)
compute(parse_term("x", s), cfg, s)$value     # 9    -- should be 2
compute(parse_term("x + 1", s), cfg, s)$value # 10   -- should be 3

cfg_bind() is function(config, symbol, value) .Call(..., as.character(symbol), as.numeric(value)). An rssn_term is an integer with a class, so as.numeric() strips the class and returns the handle. A different term therefore binds a different number unrelated to its text:

t2 <- parse_term("100", s)
cfg2 <- rssn_config() |> cfg_numeric(1e-12) |> cfg_bind("x", t2)
compute(parse_term("x", s), cfg2, s)$value    # 15 (handle of "100"), not 100

The help page says value is "The number a symbol is bound to", so either a non-numeric argument should be rejected (as it already is for a value_new() object, which fails with cannot coerce type 'environment') or a term should be evaluated first. A length-2 vector is likewise silently truncated (cfg_bind("x", c(1, 2)) binds x = 1), so the argument is not validated at all.

rssn 0.3.0, R 4.6.2 binding, Windows x86_64.

Dominant language
Rust
Stars
36
Forks
3
Avg merge
14h 51m
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Apich-Organization/rssn

All issues in Apich-Organization/rssn

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.