]> Cypherpunks repositories - gostls13.git/commit
cmd/vet: warn on unkeyed struct pointer literals
authorDaniel Martí <mvdan@mvdan.cc>
Thu, 25 Jan 2018 03:32:23 +0000 (10:32 +0700)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 21 Feb 2018 16:31:04 +0000 (16:31 +0000)
commit6ded116ab18c98cf572089c627f80fc1bb18cd0c
tree5eaf2cda23607c5f8b2ad936a9201ef521e78310
parent8fea862f425df795ea3850e9b8a5ea0800d98a32
cmd/vet: warn on unkeyed struct pointer literals

We did warn on them in some cases, but not others. In particular, if one
used a slice composite literal with struct pointer elements, and omitted
the type of an element's composite literal, it would not get any warning
even if it should get one.

The issue is that typ.Underlying() can be of type *types.Pointer. Skip
those levels of indirection before checking for a *types.Struct
underlying type.

isLocalType also needed a bit of tweaking to ignore dereferences.
Perhaps that can be rewritten now that we have type info, but let's
leave it for another time.

Fixes #23539.

Change-Id: I727a497284df1325b70d47a756519f5db1add25d
Reviewed-on: https://go-review.googlesource.com/89715
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/vet/composite.go
src/cmd/vet/testdata/composite.go