Skip to content

Commit 9b50725

Browse files
committed
Accept signed literal seq steps
1 parent 75d67e5 commit 9b50725

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

R/r2f-iterables-helpers.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@ seq_like_r2f <- function(
375375
# Used by: seq_like_r2f() (subscript context)
376376
check_subscript_range_bounds <- function(info, from, to, by_f, hoist, scope) {
377377
lit <- function(e) {
378-
if (is_wholenumber(e)) as.integer(e) else NA_integer_
378+
e <- unwrap_parens(e)
379+
if (is_scalar_integerish(e)) as.integer(e) else NA_integer_
379380
}
380381
from_lit <- lit(info$from)
381382
to_lit <- lit(info$to)

tests/testthat/test-subscript-validation.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ test_that("literal in-range bounds emit no guard; bad literals error at compile
196196
})
197197

198198
test_that("x[seq(a, b, by)] requires a literal step and guards wrong signs", {
199+
fdesc <- function(x) {
200+
declare(type(x = double(5)))
201+
x[seq(5L, 1L, by = -1L)]
202+
}
203+
expect_quick_identical(fdesc, list(as.double(1:5)))
204+
199205
# the result length divides by the step, and the C bridge evaluates it
200206
# before any runtime guard could run -> compile error
201207
fn <- function(x, k) {

0 commit comments

Comments
 (0)