Skip to content

Commit 624951c

Browse files
feat: Handle empty child values for list constants (#186)
Co-authored-by: Kirill Müller <[email protected]>
1 parent c91badf commit 624951c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ Value RApiTypes::SexpToValue(SEXP valsexp, R_len_t idx, bool typed_logical_null)
233233
auto value = SexpToValue(ts_val, child_idx);
234234
child_values.push_back(value);
235235
}
236+
if (child_values.empty()) {
237+
return Value::EMPTYLIST(RApiTypes::LogicalTypeFromRType(child_rtype, true));
238+
}
236239
return Value::LIST(std::move(child_values));
237240
}
238241
case RTypeId::STRUCT: {

tests/testthat/_snaps/relational.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@
6464
Error:
6565
! expr_comparison: Invalid comparison operator
6666

67+
# Handle zero-length lists (#186)
68+
69+
Code
70+
expr_constant(list(integer()))
71+
Message
72+
DuckDB Expression: []
73+

tests/testthat/test-relational.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,3 +897,11 @@ test_that("we don't crash with evaluation errors", {
897897
# If this succeeds, find a new query that throws a runtime error.
898898
expect_error(nrow(ans), "Error evaluating duckdb query")
899899
})
900+
901+
test_that("Handle zero-length lists (#186)", {
902+
local_edition(3)
903+
904+
expect_snapshot({
905+
expr_constant(list(integer()))
906+
})
907+
})

0 commit comments

Comments
 (0)