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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@myitcv
Copy link
Member

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

@myitcv myitcv added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 29, 2018
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone May 29, 2018
@griesemer griesemer self-assigned this May 29, 2018
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 29, 2018
@griesemer
Copy link
Contributor

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

@gopherbot
Copy link

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

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants