Skip to content

go/types: CheckExpr doesn't return partial results #34248

@muirdm

Description

@muirdm

What version of Go are you using (go version)?

$ go version
go version go1.13 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Darwin/amd64

What did you do?

I used types.CheckExpr to check the expression "foo{i}" in the package:

package fake
type foo struct {}
var _  = foo{i}

What did you expect to see?

I expected to have some way to type check resiliently and get the type for my *ast.CompositeLit.

See https://play.golang.org/p/dDqvcc-jSFM

What did you see instead?

The error for the un-type checkable "i" identifier is returned and no type checking is done. When using *types.Checker you can set the "Error" callback in the config so the type checker doesn't bail out, but CheckExpr doesn't set "Error" in the config.

I was experimenting with types.CheckExpr in gopls to provide completions in the face of certain kinds of syntax errors, but its utility is limited because it isn't resilient to errors.

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.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions