Skip to content

Assignment + ternary precedence: x = 0 if flag else 1 incorrectly nests assignment inside ternary #18

Description

@dreed-sd

x = 0 if flag else 1 should parse as x = (0 if flag else 1), but GDShrapt parses it as (x = 0) if flag else 1 — the assignment becomes the ternary's true branch.

Minimal repro

var content = "class_name T\n\nfunc f(flag: bool) -> void:\n\tvar x: int = 0\n\tx = 0 if flag else 1\n";
var tree = new GDScriptReader().ParseFileContent(content);
var stmt = tree.Methods.First().AllNodes.OfType<GDExpressionStatement>().Last();

// Expected: GDDualOperatorExpression 
// Actual: GDIfExpression 
Console.WriteLine(stmt.Expression.GetType().Name); // "GDIfExpression"

var tern = (GDIfExpression)stmt.Expression;
Console.WriteLine(tern.TrueExpression); // "x = 0" — assignment is inside the ternary

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions