Skip to content

go/parser: fails to parse an invalid switch statement #29148

Open

Description

@stamblerre

Repro case:

package main

import "go/ast"

func main() {
	var node ast.Node
	var lit *ast.CompositeLit
	switch n := node.(type) {
	case *ast.CompositeLit:
		lit = n
                lit.
	case *ast.KeyValueExpr:
	}
}

In this case, lit. case *ast.KeyValueExpr: gets parsed into an *ast.BadStmt. This is a problem for tools that need to work on broken code.

Activity

  1. stamblerre commented on Dec 7, 2018

    @stamblerre
    ContributorAuthor
  2. self-assigned this
    on Dec 7, 2018
  3. mvdan commented on Dec 9, 2018

    @mvdan
    Member

    Could be interesting to see what cmd/compile/internal/syntax does here. As far as I've seen, it does a better job with edge cases and errors. Though it doesn't seem to have a BadStmt equivalent right now.

  4. added this to the Unplanned milestone on Dec 13, 2018
  5. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Dec 13, 2018
  6. removed their assignment
    on Oct 22, 2020
  7. added
    gopls/parsingIssues related to parsing / poor parser recovery.
    on Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.gopls/parsingIssues related to parsing / poor parser recovery.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions