voltrevo/vortex

Path Sum Bug

Opened this issue · 1 comments

There is a bug in the code:

for (i:= 0; i < forbiddens:Length(); i++){
if (N == forbiddens[i]){
return [-1];
}
}
if (N == 0){
return [0];
}
as := FindPath([a, b], N - a, forbiddens);
bs := FindPath([a, b], N - b, forbiddens);
if (as[0] == -1 && bs[0] == -1){
return [-1];
}
else if (as[0] != -1){
as = [a] ++ as;
return as;
}
else if (bs[0] != -1){
bs = [b] ++ bs;
return bs;
}
return [-1];

Well done 🎉

I didn't realize stack errors would get reported as compiler bugs 😉. Here's a simpler repro case:

func stackError() => stackError() + stackError();

return stackError();

This can be fixed by treating stack errors as a special case. It's still an error but not an internal error and it shouldn't ask the user to report it. If you want, you could do the fix yourself and submit a PR, take a look at this code:

https://github.com/voltrevo/vortex/blob/master/src/Compiler.ts#L40

Otherwise I'll get to it soon. Thanks again :-).