js-slang icon indicating copy to clipboard operation
js-slang copied to clipboard

Import Cycle Detection throws unhandled error when graph is not fully a cycle

Open leeyi45 opened this issue 1 year ago • 3 comments

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.

Link to example program

leeyi45 avatar Feb 13 '24 19:02 leeyi45

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.

martin-henz avatar Feb 13 '24 22:02 martin-henz

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

leeyi45 avatar Feb 13 '24 22:02 leeyi45

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"

martin-henz avatar Feb 15 '24 01:02 martin-henz