Fix segfault on compile failure

This commit is contained in:
K. Lange 2021-01-07 12:34:44 +09:00
parent 21760c1f2d
commit 03ead15eaf

4
vm.c
View File

@ -3502,10 +3502,10 @@ KrkValue krk_interpret(const char * src, int newScope, char * fromName, char * f
if (newScope) krk_startModule(fromName);
KrkFunction * function = krk_compile(src, 0, fromFile);
krk_attachNamedObject(&vm.module->fields, "__file__", (KrkObj*)function->chunk.filename);
if (!function) return NONE_VAL();
krk_attachNamedObject(&vm.module->fields, "__file__", (KrkObj*)function->chunk.filename);
krk_push(OBJECT_VAL(function));
function->name = krk_copyString(fromName, strlen(fromName));