@@ -1271,6 +1271,37 @@ test_that("message given if same parameter is generated by macros multiple times
12711271 nimbleOptions(verbose = FALSE )
12721272})
12731273
1274+ test_that(" error when macro has use3pieces = TRUE but code is not an assignment" , {
1275+ testMacro <- nimble ::: buildMacro(
1276+ function (stoch , LHS , RHSarg , modelInfo , .env ) {
1277+ ans <- substitute(
1278+ OP(LHS , dnorm(RHSarg , 1 )),
1279+ list (LHS = LHS , RHSarg = RHSarg ,
1280+ OP = if (stoch ) as.name(' ~' ) else as.name(' <-' ))
1281+ )
1282+ list (code = ans , modelInfo = modelInfo )
1283+ },
1284+ use3pieces = TRUE , # # default
1285+ unpackArgs = TRUE # # default
1286+ )
1287+
1288+ # Code without LHS/assigment
1289+ code <- quote(testMacro(y [1 ]))
1290+
1291+ expect_error(
1292+ testMacro $ process(code , modelInfo = list (), .env = environment()),
1293+ " This macro must be used as part of an assignment"
1294+ )
1295+
1296+ code <- quote(~ testMacro(y [1 ]))
1297+
1298+ expect_error(
1299+ testMacro $ process(code , modelInfo = list (), .env = environment()),
1300+ " This macro must be used as part of an assignment"
1301+ )
1302+
1303+ })
1304+
12741305options(warn = RwarnLevel )
12751306nimbleOptions(verbose = nimbleVerboseSetting )
12761307
0 commit comments