1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-26 07:03:16 +00:00

Ensure value is of specified type or panic

This commit is contained in:
Michael Camilleri 2021-12-15 12:17:35 +09:00
parent 939d1dcae9
commit 97a8938407
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572

View File

@ -958,9 +958,14 @@ JANET_CORE_FN(cfun,
}
const uint8_t *source = NULL;
if (argc >= 3) {
source = janet_checktype(argv[2], JANET_STRING) ?
janet_unwrap_string(argv[2]) :
janet_unwrap_keyword(argv[2]);
Janet x = argv[2];
if (janet_checktype(x, JANET_STRING)) {
source = janet_unwrap_string(x);
} else if (janet_checktype(x, JANET_KEYWORD)) {
source = janet_unwrap_keyword(x);
} else {
janet_panic_type(x, 2, JANET_TFLAG_STRING | JANET_TFLAG_KEYWORD);
}
}
JanetArray *lints = (argc >= 4) ? janet_getarray(argv, 3) : NULL;
JanetCompileResult res = janet_compile_lint(argv[0], env, source, lints);