-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/structtag: recognize multiple keys per tag
As of Go 1.16 the reflect package now supports multiple keys per tag. For golang/go#40281 Fixes golang/go#43083 Change-Id: I55cdc35c857a5e73dc009c2842d7bd83c63d7712 Reviewed-on: https://go-review.googlesource.com/c/tools/+/277092 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Tim King <taking@google.com>
- Loading branch information
1 parent
6d345e8
commit abf6a1d
Showing
3 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build go1.16 | ||
|
||
package structtag_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis/analysistest" | ||
"golang.org/x/tools/go/analysis/passes/structtag" | ||
) | ||
|
||
// Test the multiple key format added in Go 1.16. | ||
|
||
func TestGo16(t *testing.T) { | ||
testdata := analysistest.TestData() | ||
analysistest.Run(t, testdata, structtag.Analyzer, "go16") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2020 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Tests for the new multiple-key struct tag format supported in 1.16. | ||
|
||
package go16 | ||
|
||
type Go16StructTagTest struct { | ||
OK int `multiple keys can:"share a value"` | ||
OK2 int `json bson xml form:"field_1,omitempty" other:"value"` | ||
} | ||
|
||
type Go16UnexportedEncodingTagTest struct { | ||
F int `json xml:"ff"` | ||
|
||
// We currently always check json first, and return after an error. | ||
f1 int `json xml:"f1"` // want "struct field f1 has json tag but is not exported" | ||
f2 int `xml json:"f2"` // want "struct field f2 has json tag but is not exported" | ||
f3 int `xml bson:"f3"` // want "struct field f3 has xml tag but is not exported" | ||
f4 int `bson xml:"f4"` // want "struct field f4 has xml tag but is not exported" | ||
} | ||
|
||
type Go16DuplicateFields struct { | ||
JSONXML int `json xml:"c"` | ||
DuplicateJSONXML int `json xml:"c"` // want "struct field DuplicateJSONXML repeats json tag .c. also at go16.go:25" "struct field DuplicateJSONXML repeats xml tag .c. also at go16.go:25" | ||
} |