Skip to content

go/parser: StructType.End() can underflow the File #66683

Open
@adonovan

Description

@adonovan

A struct type with a missing close brace has an StructType.End pos of zero. That means the enclosing nodes such as ReturnStmt may also have a computed End that is zero, or perhaps slightly larger:

Screenshot 2024-04-04 at 2 43 08 PM

I believe this is the root cause of at least some of the many gopls crashes recorded in #64547.

Ultimately this is a problem of parser error recovery. We need to establish the invariants that:

  • all tree nodes have valid Pos/End positions; and
  • all tree nodes have nested Pos/End subranges (with a possible exception for the func keyword in FuncDecl/FuncType).

See also:

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.RefactoringIssues related to refactoring toolsgopls/parsingIssues related to parsing / poor parser recovery.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions