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

2 last statements in single top level block doesn't error recover well #298

Open
toxamin opened this issue Apr 12, 2024 · 5 comments · Fixed by #302
Open

2 last statements in single top level block doesn't error recover well #298

toxamin opened this issue Apr 12, 2024 · 5 comments · Fixed by #302
Labels
bug Something isn't working

Comments

@toxamin
Copy link

toxamin commented Apr 12, 2024

test case:

print("xd")
continue -- this can be replaced with break/return
print("xd2")

parsing this does not produce any errors (imo it should).
however, even if this should be parsed, the location of the laststmt in question is ambiguous:
if it's continue, then we keep parsing statements, so the continue statement "teleports" to the end
if it's return, then the other statements get stripped (parser is no longer lossless)
etc. etc.

of course it's possible to determine the position based on tokens, but it isn't very convenient

@Kampfkarren Kampfkarren added the bug Something isn't working label Apr 14, 2024
@Kampfkarren
Copy link
Owner

Your example does error for me. Is this on master or on the current crate?

@toxamin
Copy link
Author

toxamin commented Apr 14, 2024

latest master, my code:

use full_moon::ast::AstResult;
use full_moon::{LuaVersion, parse_fallible};

fn main() {
    let code = "
        print(\"xd\")
        continue
        print(\"xd2\")
    ";
    let raw_result: AstResult = parse_fallible(&code, LuaVersion::luau());

    raw_result.errors().iter().for_each(|e| println!("{}", e));
    println!("done");
}

@Kampfkarren
Copy link
Owner

I'm surprised we didn't have a regression test for this. Good find

@JohnnyMorganz
Copy link
Collaborator

Note this is specific to the top-level block parsing, and does not occur when parsing inside of nested blocks (e.g., loops)

@JohnnyMorganz
Copy link
Collaborator

Reopening as the error recovery part isn't completely solved yet, as we lose data

@JohnnyMorganz JohnnyMorganz changed the title laststmt behavior 2 last statements in single top level block doesn't error recover well Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants