Skip to content

Commit

Permalink
Merge pull request #78 from moodymudskipper/b-62-env-issue
Browse files Browse the repository at this point in the history
fix environment issue
  • Loading branch information
moodymudskipper authored Jan 2, 2025
2 parents e5f143f + 2dc0e35 commit f3b1470
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/dep-suggests-matrix.json

This file was deleted.

1 change: 0 additions & 1 deletion .github/versions-matrix.json

This file was deleted.

5 changes: 3 additions & 2 deletions R/02_declare.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ check_arg <- function(.arg, .assertion, ..., .bind = FALSE) {
#' @export
declare <- function(x, assertion, value, const = FALSE) {
pf <- parent.frame()
f_env <- new.env(parent = pf)

if(missing(assertion)) {
assertion_quoted <- infer_implicit_assignment_call(value)
Expand Down Expand Up @@ -163,7 +164,7 @@ declare <- function(x, assertion, value, const = FALSE) {
val
}
},
envir = pf),
envir = f_env),
list(VAR_NM = x, VALUE = value)
))
} else {
Expand All @@ -190,7 +191,7 @@ declare <- function(x, assertion, value, const = FALSE) {
}
val
}
}, envir = pf),
}, envir = f_env),
list (ASSERTION = assertion_quoted, VAR_NM = x, VALUE = value)
)
)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-declare.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ test_that("declare works", {
expect_equal(Double() ? x <- 1, 1)
expect_error(Double() ? x <- 1L)
})

test_that("values are declared in separate environments", {
typed::Integer() ? a
typed::Integer() ? b

a <- 1L
b <- 2L
expect_equal(a, 1L)
})

0 comments on commit f3b1470

Please sign in to comment.