@@ -57,21 +57,21 @@ test_that("no names add to unnamed elements", {
5757 x <- 1 : 3
5858 expect_equal(qfn(x ), fn(x ))
5959})
60- test_that(" mixed named and symbols list work" , {
60+
61+
62+ test_that(" mixed named and unnamed list work" , {
6163 fn <- function (x ) {
6264 declare(type(x = integer(n )))
6365 y <- x + 1L
6466 z <- x + 2L
65- list (abc = y , z )
67+ list (y , abc = z , x )
6668 }
6769 qfn <- quick(fn )
6870 x <- 1 : 3
6971 expect_equal(qfn(x ), fn(x ))
7072})
7173
7274
73-
74-
7575test_that(" errors if list is used outside return pattern [r2f error]" , {
7676 # # list not last or second to last
7777 fn <- function (x ) {
@@ -85,16 +85,44 @@ test_that("errors if list is used outside return pattern [r2f error]", {
8585 expect_error(quick(fn ), " Unsupported function: list" )
8686 # # List is being accessed
8787 fn <- function (x ) {
88- declare(
89- type(x = integer(n )),
90- type(y = integer(n )),
91- type(z = integer(n ))
92- )
88+ declare(type(x = integer(n )))
9389 y <- x + 1
9490 z <- x + 2
9591 out <- list (y = y , z = z )
9692 out $ y
9793 }
9894 expect_error(quick(fn ), " Unsupported function: list" )
95+ })
96+
97+
98+ test_that(" errors om nested list and non-symbols [validate_list_symbols]" , {
99+ # # Nested lists
100+ fn <- function (x ) {
101+ declare(type(x = integer(n )))
102+ y <- x + 1
103+ z <- x + 2
104+ out <- list (y = y , z = z , list (x = x ))
105+ out
106+ }
107+ x <- 1 : 3
108+ expect_error(quick(fn ), " all elements of the list must be symbols" )
109+
110+ # # non-symbols in list
111+ fn <- function (x ) {
112+ declare(type(x = integer(n )))
113+ y <- x + 1
114+ z <- x + 2
115+ list (a = 1L , b = 2L )
116+ }
117+ x <- 1 : 3
118+ expect_error(quick(fn ), " all elements of the list must be symbols" )
99119
120+ fn <- function (x ) {
121+ declare(type(x = integer(n )))
122+ y <- x + 1
123+ z <- x + 2
124+ list (1L )
125+ }
126+ x <- 1 : 3
127+ expect_error(quick(fn ), " all elements of the list must be symbols" )
100128})
0 commit comments