DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.51k stars 31 forks source link

Miscompile when attempting to `|> throw` #1513

Open bbrk24 opened 3 hours ago

bbrk24 commented 3 hours ago

What the heck is going on here

try
    ;
catch err
    if err <? RangeError
        new StackTracingError
            `${err.message}`
            cause: err
        ||> .addCall raw
        |> throw
    throw err
(() => {
  throw (() => {
    throw err;
  })();
})()(
  (() => {
    try {
    } catch (err) {
      let ref;
      return err instanceof RangeError
        ? ((ref = new StackTracingError(`${err.message}`, {
            cause: err,
          })).addCall(raw),
          ref)
        : void 0;
    }
  })(),
);
bbrk24 commented 3 hours ago

Oh, I see what's happened. Simple |> throw isn't supported, so it instead parses as this:

(
    try
        ;
    catch err
        if err <? RangeError
            new StackTracingError
                `${err.message}`
                cause: err
            ||> .addCall raw
) |> throw throw err
edemaine commented 1 hour ago

|> throw sounds like a useful and simple addition (similar to |> return, |> await, etc.). Do you want to work on it?

bbrk24 commented 1 hour ago

I can certainly take a look at it later today.