Skip to content

Commit 3057c42

Browse files
authored
NA + 1i is not syntactic literal (#1829)
Fixes #1828.
1 parent 150d522 commit 3057c42

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

R/expr.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ is_syntactic_literal <- function(x) {
133133
length(x) == 1 && is.null(attributes(x)) && (is.na(x) || x >= 0)
134134
},
135135
complex = {
136-
length(x) == 1 && is.null(attributes(x)) && (is.na(x) || (Re(x) == 0 && Im(x) >= 0))
136+
length(x) == 1 &&
137+
is.null(attributes(x)) &&
138+
(
139+
(is.na(Re(x)) && is.na(Im(x))) ||
140+
(!is.na(x) && Re(x) == 0 && Im(x) >= 0)
141+
)
137142
},
138143
FALSE
139144
)

tests/testthat/test-expr.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,10 @@ test_that("negative numbers are not syntactic", {
144144
expect_false(is_syntactic_literal(-1))
145145
expect_false(is_syntactic_literal(-1L))
146146
expect_false(is_syntactic_literal(-1i))
147+
})
148+
149+
test_that("NA + 1i is not syntactic", {
150+
skip_if_not_installed("base", "4.4")
151+
expect_false(is_syntactic_literal(NA + 1i))
152+
expect_false(is_syntactic_literal(NA - 1i))
147153
})

0 commit comments

Comments
 (0)