Skip to content

Commit e5fee11

Browse files
authored
Make is_syntactic_literal() more strict (#1824)
Add an `attributes()` check to `is_syntactic_literal()` to ensure that syntactic-literal-like objects such as factors and arrays are not treated as syntactic literals. Fixes #1817.
1 parent 0da36b8 commit e5fee11

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* C code no longer calls `memcpy()` and `memset()` on 0-length R object memory
44
(#1797).
5+
* `is_syntactic_literal()` returns `FALSE` for objects with attributes, such as `array(1)` or `factor("x")` (#1817, @jonthegeek).
56

67

78
# rlang 1.1.6

R/expr.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ is_syntactic_literal <- function(x) {
129129
integer = ,
130130
double = ,
131131
character = {
132-
length(x) == 1
132+
length(x) == 1 && is.null(attributes(x))
133133
},
134134

135135
complex = {

tests/testthat/test-expr.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,11 @@ test_that("is_expression() detects attributes (#1475)", {
130130
NULL
131131
})))
132132
})
133+
134+
test_that("arrays are not syntactic", {
135+
expect_false(is_syntactic_literal(array(1)))
136+
})
137+
138+
test_that("factors are not syntactic", {
139+
expect_false(is_syntactic_literal(factor("x")))
140+
})

0 commit comments

Comments
 (0)