You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think that odin/parser when parsing declarations assumes that after each declaration there will be a \n, because the end position for declarations is extended by one.
When there is no newline after the last declaration, and I try to print it, using the offsets, I get an out of bounds error.
code
package main
import"core:fmt"import"core:odin/ast"import"core:odin/parser"
main :: proc() {
pkg, ok := parser.collect_package(".")
if !ok dopanic("Failed to collect package\n")
ok = parser.parse_package(pkg)
if !ok dopanic("Failed to parse package\n")
for file_name, file in pkg.files {
for decl in file.decls {
fmt.printf("%s\n", file.src[decl.pos.offset:decl.end.offset]) // <- out of bounds error
}
}
} // <- no newline afterwards
error
$ odin run .
import "core:fmt"
import "core:odin/ast"
import "core:odin/parser"
/path/main.odin(16:40) Invalid slice indices 82:443 is out of range 0..<442
Illegal instruction (core dumped)
I think that
odin/parser
when parsing declarations assumes that after each declaration there will be a\n
, because the end position for declarations is extended by one.When there is no newline after the last declaration, and I try to print it, using the offsets, I get an out of bounds error.
code
error
report
I know that this is an issue with my code, but the praser could probably prevent that?
It's weird to have nodes that extend the file bounds.
The text was updated successfully, but these errors were encountered: