Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern Catching Gone Wrong #1485

Open
bbrk24 opened this issue Oct 22, 2024 · 3 comments
Open

Pattern Catching Gone Wrong #1485

bbrk24 opened this issue Oct 22, 2024 · 3 comments

Comments

@bbrk24
Copy link
Contributor

bbrk24 commented Oct 22, 2024

What on earth is this miscompile

try
  foo()
catch e <? RangeError
  bar(e)
(() => {
  try {
    return foo();
  } catch (e) {
    return;
  }
})() instanceof RangeError(bar(e));
@bbrk24
Copy link
Contributor Author

bbrk24 commented Oct 22, 2024

Oh, I see what's happening. Adding parens and changing whitespace for clarity, though I'm not sure if this version still parses:

(
  try
    foo
  catch e
) <? RangeError bar(e)

@edemaine
Copy link
Collaborator

It's like this:

(try
  foo()
catch e) <? RangeError
  bar(e)

It's not that crazy, given what patterns are currently supported... But obviously not what you wanted. I think mainly we need to implement this form of pattern.

Maybe we also want to forbid content on the same line as a try/catch block, but I could also imagine that it might be useful sometimes...

@bbrk24
Copy link
Contributor Author

bbrk24 commented Oct 22, 2024

If nothing else, content before the try is definitely useful. Example:

    ast := try parse input catch err
        if err <? AssertionError
            console.error 'DEBUG ASSERTION FAILED'
            console.error err
        else
            console.error makeErrorString err
        return 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants