| 1 |
package a |
| 2 |
|
| 3 |
import "a/internal" |
| 4 |
|
| 5 |
// Functions. |
| 6 |
|
| 7 |
func f() { |
| 8 |
One() // want `Call of a.One should be inlined` |
| 9 |
|
| 10 |
new(T).Two() // want `Call of \(a.T\).Two should be inlined` |
| 11 |
} |
| 12 |
|
| 13 |
type T struct{} |
| 14 |
|
| 15 |
//go:fix inline |
| 16 |
func One() int { return one } // want One:`goFixInline a.One` |
| 17 |
|
| 18 |
const one = 1 |
| 19 |
|
| 20 |
//go:fix inline |
| 21 |
func (T) Two() int { return 2 } // want Two:`goFixInline \(a.T\).Two` |
| 22 |
|
| 23 |
// Constants. |
| 24 |
|
| 25 |
const Uno = 1 |
| 26 |
|
| 27 |
//go:fix inline |
| 28 |
const In1 = Uno // want In1: `goFixInline const "a".Uno` |
| 29 |
|
| 30 |
const ( |
| 31 |
no1 = one |
| 32 |
|
| 33 |
//go:fix inline |
| 34 |
In2 = one // want In2: `goFixInline const "a".one` |
| 35 |
) |
| 36 |
|
| 37 |
//go:fix inline |
| 38 |
const ( |
| 39 |
in3 = one |
| 40 |
in4 = one |
| 41 |
bad1 = 1 // want `invalid //go:fix inline directive: const value is not the name of another constant` |
| 42 |
) |
| 43 |
|
| 44 |
//go:fix inline |
| 45 |
const in5, |
| 46 |
in6, |
| 47 |
bad2 = one, one, |
| 48 |
one + 1 // want `invalid //go:fix inline directive: const value is not the name of another constant` |
| 49 |
|
| 50 |
// Make sure we don't crash on iota consts, but still process the whole decl. |
| 51 |
// |
| 52 |
//go:fix inline |
| 53 |
const ( |
| 54 |
a = iota // want `invalid //go:fix inline directive: const value is iota` |
| 55 |
b |
| 56 |
in7 = one |
| 57 |
) |
| 58 |
|
| 59 |
func _() { |
| 60 |
x := In1 // want `Constant In1 should be inlined` |
| 61 |
x = In2 // want `Constant In2 should be inlined` |
| 62 |
x = in3 // want `Constant in3 should be inlined` |
| 63 |
x = in4 // want `Constant in4 should be inlined` |
| 64 |
x = in5 // want `Constant in5 should be inlined` |
| 65 |
x = in6 // want `Constant in6 should be inlined` |
| 66 |
x = in7 // want `Constant in7 should be inlined` |
| 67 |
x = no1 |
| 68 |
_ = x |
| 69 |
|
| 70 |
in1 := 1 // don't inline lvalues |
| 71 |
_ = in1 |
| 72 |
} |
| 73 |
|
| 74 |
const ( |
| 75 |
x = 1 |
| 76 |
//go:fix inline |
| 77 |
in8 = x |
| 78 |
) |
| 79 |
|
| 80 |
//go:fix inline |
| 81 |
const D = internal.D // want D: `goFixInline const "a/internal".D` |
| 82 |
|
| 83 |
func shadow() { |
| 84 |
var x int // shadows x at package scope |
| 85 |
|
| 86 |
//go:fix inline |
| 87 |
const a = iota // want `invalid //go:fix inline directive: const value is iota` |
| 88 |
|
| 89 |
const iota = 2 |
| 90 |
// Below this point, iota is an ordinary constant. |
| 91 |
|
| 92 |
//go:fix inline |
| 93 |
const b = iota |
| 94 |
|
| 95 |
x = a // a is defined with the predeclared iota, so it cannot be inlined |
| 96 |
x = b // want `Constant b should be inlined` |
| 97 |
|
| 98 |
// Don't offer to inline in8, because the result, "x", would mean something different |
| 99 |
// in this scope than it does in the scope where in8 is defined. |
| 100 |
x = in8 |
| 101 |
|
| 102 |
_ = x |
| 103 |
} |
| 104 |
|
| 105 |
// Type aliases |
| 106 |
|
| 107 |
//go:fix inline |
| 108 |
type A = T // want A: `goFixInline alias` |
| 109 |
|
| 110 |
var _ A // want `Type alias A should be inlined` |
| 111 |
|
| 112 |
//go:fix inline |
| 113 |
type AA = // want AA: `goFixInline alias` |
| 114 |
A // want `Type alias A should be inlined` |
| 115 |
|
| 116 |
var _ AA // want `Type alias AA should be inlined` |
| 117 |
|
| 118 |
//go:fix inline |
| 119 |
type ( |
| 120 |
B = []T // want B: `goFixInline alias` |
| 121 |
C = map[*string][]error // want C: `goFixInline alias` |
| 122 |
) |
| 123 |
|
| 124 |
var _ B // want `Type alias B should be inlined` |
| 125 |
var _ C // want `Type alias C should be inlined` |
| 126 |
|
| 127 |
//go:fix inline |
| 128 |
type E = map[[Uno]string][]*T // want `invalid //go:fix inline directive: array types not supported` |
| 129 |
|
| 130 |
var _ E // nothing should happen here |
| 131 |
|
| 132 |
// literal array lengths are OK |
| 133 |
// |
| 134 |
//go:fix inline |
| 135 |
type EL = map[[2]string][]*T // want EL: `goFixInline alias` |
| 136 |
|
| 137 |
var _ EL // want `Type alias EL should be inlined` |
| 138 |
|
| 139 |
//go:fix inline |
| 140 |
type F = map[internal.T]T // want F: `goFixInline alias` |
| 141 |
|
| 142 |
var _ F // want `Type alias F should be inlined` |
| 143 |
|
| 144 |
//go:fix inline |
| 145 |
type G = []chan *internal.T // want G: `goFixInline alias` |
| 146 |
|
| 147 |
var _ G // want `Type alias G should be inlined` |
| 148 |
|
| 149 |
// local shadowing |
| 150 |
func _() { |
| 151 |
type string = int |
| 152 |
const T = 1 |
| 153 |
|
| 154 |
var _ B // nope: B's RHS contains T, which is shadowed |
| 155 |
var _ C // nope: C's RHS contains string, which is shadowed |
| 156 |
} |
| 157 |
|
| 158 |
// local inlining |
| 159 |
func _[P any]() { |
| 160 |
const a = 1 |
| 161 |
//go:fix inline |
| 162 |
const b = a |
| 163 |
|
| 164 |
x := b // want `Constant b should be inlined` |
| 165 |
|
| 166 |
//go:fix inline |
| 167 |
type u = []P |
| 168 |
|
| 169 |
var y u // want `Type alias u should be inlined` |
| 170 |
|
| 171 |
_ = x |
| 172 |
_ = y |
| 173 |
} |
| 174 |
|
| 175 |
// generic type aliases |
| 176 |
|
| 177 |
//go:fix inline |
| 178 |
type ( |
| 179 |
Mapset[T comparable] = map[T]bool // want Mapset: `goFixInline alias` |
| 180 |
Pair[X, Y any] = struct { // want Pair: `goFixInline alias` |
| 181 |
X X |
| 182 |
Y Y |
| 183 |
} |
| 184 |
) |
| 185 |
|
| 186 |
var _ Mapset[int] // want `Type alias Mapset\[int\] should be inlined` |
| 187 |
|
| 188 |
var _ Pair[T, string] // want `Type alias Pair\[T, string\] should be inlined` |
| 189 |
|
| 190 |
func _[V any]() { |
| 191 |
//go:fix inline |
| 192 |
type M[K comparable] = map[K]V |
| 193 |
|
| 194 |
var _ M[int] // want `Type alias M\[int\] should be inlined` |
| 195 |
} |