Skip to content

Is node_has_error() supposed to return true on terminal error nodes? #3623

Open
@DavisVaughan

Description

Problem

Consider the following example using the R bindings to tree-sitter (I can try and make a Rust tree-sitter test for this if needed)

I was expecting node_has_error() to return true on the inner terminal ERROR node produced here.

According to the docs it should:

Check if the node is a syntax error or contains any syntax errors

library(treesitter)

text <- "1 + }"

parser <- parser(treesitter.r::language())

tree <- parser_parse(parser, text)
root <- tree_root_node(tree)

root
#> <tree_sitter_node>
#> 
#> ── Text ────────────────────────────────────────────────────────────────────────
#> 1 + }
#> 
#> ── S-Expression ────────────────────────────────────────────────────────────────
#> (program [(0, 0), (0, 5)]
#>   (float [(0, 0), (0, 1)])
#>   (ERROR [(0, 2), (0, 5)]
#>     "+" [(0, 2), (0, 3)]
#>     (ERROR [(0, 4), (0, 5)])
#>   )
#> )

outer_error <- root |>
  node_child(2)

outer_error
#> <tree_sitter_node>
#> 
#> ── Text ────────────────────────────────────────────────────────────────────────
#> + }
#> 
#> ── S-Expression ────────────────────────────────────────────────────────────────
#> (ERROR [(0, 2), (0, 5)]
#>   "+" [(0, 2), (0, 3)]
#>   (ERROR [(0, 4), (0, 5)])
#> )

# These make sense
node_is_error(outer_error)
#> [1] TRUE
node_has_error(outer_error)
#> [1] TRUE

inner_error <- outer_error |>
  node_child(2)

inner_error
#> <tree_sitter_node>
#> 
#> ── Text ────────────────────────────────────────────────────────────────────────
#> }
#> 
#> ── S-Expression ────────────────────────────────────────────────────────────────
#> (ERROR [(0, 4), (0, 5)])

# According to the docs, `node_has_error()` should return `TRUE`?
node_is_error(inner_error)
#> [1] TRUE
node_has_error(inner_error)
#> [1] FALSE

Steps to reproduce

See above

Expected behavior

Return true anytime node_is_error() also returns true

Tree-sitter version (tree-sitter --version)

tree-sitter 0.23

Operating system/version

macOS

Activity

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

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions