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

Aperta
#369 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
67/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
r, rust
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
36
Fork
3
Merge medio
14h 51m
PR unite (30g)
29

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Apich-Organization/rssn

Tutte le issue di Apich-Organization/rssn

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.