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

Rowan upgrade to 0.16.0 breaks prev_sibling behaviour #175

Open
MalteJanz opened this issue Nov 21, 2024 · 1 comment
Open

Rowan upgrade to 0.16.0 breaks prev_sibling behaviour #175

MalteJanz opened this issue Nov 21, 2024 · 1 comment

Comments

@MalteJanz
Copy link
Contributor

MalteJanz commented Nov 21, 2024

Discovered by MalteJanz/ludtwig#122

The failed test pipeline contains a bunch of issues related to the rowan upgrade that might need further investigation. But I think the easiest failing test is the following:

(can be found here)

    #[test]
    fn it_should_not_panic_on_prev_sibling_call() {
        let parse = parse("<div>a<hr/></div>");
        let root = SyntaxNode::new_root(parse.green_node);
        // println!("{}", debug_tree(&root));

        let prev = root.prev_sibling();
        // println!("prev sibling: {:?}", prev);
        assert!(prev.is_none());

        let child: HtmlTag = support::child(&root).unwrap();
        let prev = child.syntax().prev_sibling();
        // println!("{:?} prev sibling: {:?}", child, prev);
        assert!(prev.is_none());

        let child: HtmlTag = support::child(child.body().unwrap().syntax()).unwrap();
        let prev = child.syntax().prev_sibling();
        // println!("{:?} prev sibling: {:?}", child, prev);
        assert!(prev.is_some());
    }

Btw: I wrote this test while fixing my previous rowan contribution, see #143 . It basically came down to a off-by-one error which might regressed with the latest version, see initial issue: #139

Test output:

---- tests::it_should_not_panic_on_prev_sibling_call stdout ----
thread 'tests::it_should_not_panic_on_prev_sibling_call' panicked at crates/ludtwig-parser/src/lib.rs:152:9:
assertion failed: prev.is_some()

Which points to the last assertion and last line of the test above. Seems like the sibling somehow got lost 🤔

Test explaination

The parsing input:

<div>a<hr/></div>

produces the following tree:

Note: remember the HTML_TEXT node with the "a" word token next to the HTML_TAG node ("hr" tag)

The first declaration of child ends up as the following tree (the outer div):

And doesn't have a previous sibling as expected.

Next up it get's the body of that div tag (isn't stored in a variable), which also looks like expected:

And inside that it get's the first tag which ends up in the second declared child variable:

As expected that's the <hr/> tag. And now comes the previously working call to prev_sibling on that exact node, which surprisingly ends up with none instead of the HTML_TEXT node.

The same test and parser implementation was succeeding in rowan 0.15.16

@MalteJanz
Copy link
Contributor Author

MalteJanz commented Nov 21, 2024

@milianw Might be related to your PR #171 as it slightly changed the prev_sibling implementation 🤔
https://github.com/rust-analyzer/rowan/pull/171/files#diff-d652bc172cf95622c9c34f43bd6ed9a6c27f042945f710cb9025cae7b12dd579L393

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

No branches or pull requests

1 participant