Skip to content

Parser fails to parse parapoly struct when opening bracket is on a new line #2205

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

Open
jlreymendez opened this issue Nov 21, 2022 · 0 comments
Labels

Comments

@jlreymendez
Copy link
Contributor

jlreymendez commented Nov 21, 2022

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}}
@github-actions github-actions bot added the stale label Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant