Debian Codegraph @

go/analysis/passes/inline/testdata/src/issue78088.txtar

raw
1 This test verifies that the inliner does not insert unnecessary parentheses when
2 forming the type arguments of a call, nor in composite literal expressions
3 where parentheses are not allowed.
4
5 -- go.mod --
6 module example.com
7 go 1.18
8
9 -- e/e.go --
10 //go:build go1.26
11 package e
12
13 import "errors"
14
15 //go:fix inline
16 func As[T error](err error) (T, bool) { // want As:"goFixInline e.As"
17 return errors.AsType[T](err)
18 }
19
20 -- f/f.go --
21 //go:build go1.26
22 package f
23
24 import (
25 "io/fs"
26 "example.com/e"
27 )
28
29 func AsPathError(err error) (*fs.PathError, bool) {
30 return e.As[*fs.PathError](err) // want "Call of e.As should be inlined"
31 }
32
33 -- f/f.go.golden --
34 //go:build go1.26
35 package f
36
37 import (
38 "errors"
39 "io/fs"
40 )
41
42 func AsPathError(err error) (*fs.PathError, bool) {
43 return errors.AsType[*fs.PathError](err) // want "Call of e.As should be inlined"
44 }
45
46 -- g/g.go --
47 package g
48
49 //go:fix inline
50 func MapLiteral[T ~map[string]int]() T { // want MapLiteral:"goFixInline g.MapLiteral"
51 return T{"k": 1}
52 }
53
54 //go:fix inline
55 func SliceLiteral[T ~[]int]() T { // want SliceLiteral:"goFixInline g.SliceLiteral"
56 return T{1, 2, 3}
57 }
58
59 -- h/h.go --
60 package h
61
62 import "example.com/g"
63
64 func CallLiterals() {
65 _ = g.MapLiteral[map[string]int]() // want "Call of g.MapLiteral should be inlined"
66 _ = g.SliceLiteral[[]int]() // want "Call of g.SliceLiteral should be inlined"
67 }
68
69 -- h/h.go.golden --
70 package h
71
72 func CallLiterals() {
73 _ = map[string]int{"k": 1} // want "Call of g.MapLiteral should be inlined"
74 _ = []int{1, 2, 3} // want "Call of g.SliceLiteral should be inlined"
75 }