Odin
Odin copied to clipboard
Parser fails to parse parapoly struct when opening bracket is on a new line
Context
The parser fails to correctly parse a parapoly struct when the opening bracket is not in the same line as the struct declaration. Instead of receiving a correct field list for the struct we get a Bad_Expr node.
Odin: dev-2022-11:382bd876
OS: Windows 10 Professional (version: 21H2), build 19044.2251
CPU: Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz
RAM: 32706 MiB
Expected Behavior
Brackets can be in different lines for compilation so the parser should also correctly parse this.
Current Behavior
Parser returns a Bad_Expr.
Failure Information (for bugs)
Step 1: write the following code into a file inside a directory of its own.
Step 2: run the code using odin run <filename.odin> -file -ignore-unknown-attributes
Step 3: see the location of the bad expression and how the first parapoly struct didn't have the same issue.
package main
import "core:odin/parser"
import "core:odin/ast"
import "core:fmt"
main :: proc()
{
p := parser.Parser{}
pkg, ok := parser.parse_package_from_path(".", &p)
if !ok
{
fmt.println("error")
return
}
ast.inspect(&pkg.node, inspect_func)
}
inspect_func :: proc(n : ^ast.Node) -> bool
{
if n == nil do return true
#partial switch d in n.derived {
case ^ast.Bad_Expr:
fmt.println(d)
}
return true
}
@meta
Parapoly_Ok :: struct($T : typeid) {
ok : int
}
@meta
Parapoly_Bad :: struct($T: typeid)
{
ok : int
}
$> odin run parse-error.odin -file -ignore-unknown-attributes
&Bad_Expr{node = Expr{expr_base = Node{pos = Pos{file = ".\\parse-error.odin", offset = 591, line = 38, column = 1}, end = Pos{file = ".\\parse-error.odin", offset = 592, line = 38, column = 2}, state_flags = Node_State_Flags{}, derived = 0x1D6E16FC898}, derived_expr = 0x1D6E16FC898}}