Skip to content
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

go/types: "incorrect" number of fields returned for struct that does not fully type-check #25627

Closed
myitcv opened this issue May 29, 2018 · 2 comments

Comments

@myitcv
Copy link
Member

@myitcv myitcv commented May 29, 2018

Please answer these questions before submitting your issue. Thanks!

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

1.10.2
tip 29957c52df

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build680398822=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/wedrTlVT2kD

What did you expect to see?

Ideally I would like to see:

A NumFields(): 2
B NumFields(): 2
C NumFields(): 2

What did you see instead?

A NumFields(): 2
B NumFields(): 2
C NumFields(): 1

This example deliberately does not type-check. So I realise the information returned by go/types is best-effort. But the problem with the *go/types.Struct returned for C is that it's partially complete, and I have no way of telling.

Would it be possible to return the correct number of fields in this situation and have the field that does not type check be of an invalid type?

/cc @griesemer @mvdan

@griesemer
Copy link
Contributor

@griesemer griesemer commented May 29, 2018

The fix should be simple. At the moment, struct fields with errors are simply dropped on the floor.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented May 29, 2018

Change https://golang.org/cl/115115 mentions this issue: go/types: add struct fields with invalid type if field has errors

Loading

@gopherbot gopherbot closed this in b28e33d May 29, 2018
@golang golang locked and limited conversation to collaborators May 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants