js-slang
js-slang copied to clipboard
Import Cycle Detection throws unhandled error when graph is not fully a cycle
Consider the following set of programs
// /a.js
import { b } from './b.js';
b;
// /b.js
import { a } from './a.js';
a;
// /program.js
import { a } from './a.js';
a;
Running /program.js
causes the directed graph's cycle finder to throws an unhandled error "Node '/playground/program.js' has no incoming edges. This should never happen."
The tests in js-slang
account for when all files together form some cycle. In this case however, the cycle only exists between /a.js
and /b.js
, so the entrypoint program /program.js
is not part of that cycle.
Does the program to be run need to be part of the cycle? In my view, importing a module that cyclically depends on some other module is ill-defined.
Does the program to be run need to be part of the cycle? In my view, importing a module that cyclically depends on some other module is ill-defined.
I don't have a particular opinion on this, just that this specific condition needs to be handled gracefully
I see. We should catch this error and display a more reasonable error message. Something like: "program /playground/program.js has cyclic dependencies in its import declarations"