Skip to content

Commit 717f185

Browse files
committed
simple: valid struct conversion depends on targeted Go version
1 parent 670bf5f commit 717f185

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

simple/lint.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,14 @@ func (c *Checker) LintSimplerStructConversion(j *lint.Job) {
10111011
if typ1 == typ2 {
10121012
return true
10131013
}
1014-
if !structsIdentical(s1, s2) {
1015-
return true
1014+
if IsGoVersion(j, 8) {
1015+
if !types.IdenticalIgnoreTags(s1, s2) {
1016+
return true
1017+
}
1018+
} else {
1019+
if !types.Identical(s1, s2) {
1020+
return true
1021+
}
10161022
}
10171023
j.Errorf(node, "should convert %s (type %s) to %s instead of using struct literal",
10181024
ident.Name, typ2.Obj().Name(), typ1.Obj().Name())

simple/lint17.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

simple/lint18.go

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pkg
2+
3+
type t1 struct {
4+
a int
5+
b int
6+
}
7+
8+
type t2 struct {
9+
a int
10+
b int
11+
}
12+
13+
type t3 struct {
14+
a int `tag`
15+
b int `tag`
16+
}
17+
18+
func fn() {
19+
v1 := t1{1, 2}
20+
_ = t2{v1.a, v1.b} // MATCH /should convert v1/
21+
_ = t3{v1.a, v1.b}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package pkg
2+
3+
type t1 struct {
4+
a int
5+
b int
6+
}
7+
8+
type t2 struct {
9+
a int
10+
b int
11+
}
12+
13+
type t3 struct {
14+
a int `tag`
15+
b int `tag`
16+
}
17+
18+
func fn() {
19+
v1 := t1{1, 2}
20+
_ = t2{v1.a, v1.b} // MATCH /should convert v1/
21+
_ = t3{v1.a, v1.b} // MATCH /should convert v1/
22+
}

0 commit comments

Comments
 (0)