| 1 |
//go:build go1.26 |
| 2 |
|
| 3 |
package newexpr |
| 4 |
|
| 5 |
// intVar returns a new var whose value is i. |
| 6 |
// |
| 7 |
//go:fix inline |
| 8 |
func intVar(i int) *int { return new(i) } // want `intVar can be an inlinable wrapper around new\(expr\)` intVar:"newlike" |
| 9 |
|
| 10 |
//go:fix inline |
| 11 |
func int64Var(i int64) *int64 { return new(i) } // want `int64Var can be an inlinable wrapper around new\(expr\)` int64Var:"newlike" |
| 12 |
|
| 13 |
//go:fix inline |
| 14 |
func stringVar(s string) *string { return new(s) } // want `stringVar can be an inlinable wrapper around new\(expr\)` stringVar:"newlike" |
| 15 |
|
| 16 |
//go:fix inline |
| 17 |
func varOf[T any](x T) *T { return new(x) } // want `varOf can be an inlinable wrapper around new\(expr\)` varOf:"newlike" |
| 18 |
|
| 19 |
//go:fix inline |
| 20 |
func alreadyAnnotated[T any](x T) *T { return new(x) } // want `alreadyAnnotated can be an inlinable wrapper around new\(expr\)` alreadyAnnotated:"newlike" |
| 21 |
|
| 22 |
var ( |
| 23 |
s struct { |
| 24 |
int |
| 25 |
string |
| 26 |
} |
| 27 |
_ = new(123) // want `call of intVar\(x\) can be simplified to new\(x\)` |
| 28 |
_ = int64Var(123) // nope: implicit conversion from untyped int to int64 |
| 29 |
_ = new("abc") // want `call of stringVar\(x\) can be simplified to new\(x\)` |
| 30 |
_ = new(s) // want `call of varOf\(x\) can be simplified to new\(x\)` |
| 31 |
_ = new(123) // want `call of varOf\(x\) can be simplified to new\(x\)` |
| 32 |
_ = new(int64(123)) // want `call of varOf\(x\) can be simplified to new\(x\)` |
| 33 |
_ = new(123) // want `call of varOf\(x\) can be simplified to new\(x\)` |
| 34 |
_ = varOf[int64](123) // nope: implicit conversion from untyped int to int64 |
| 35 |
_ = new( // want `call of varOf\(x\) can be simplified to new\(x\)` |
| 36 |
new(123)) // want `call of varOf\(x\) can be simplified to new\(x\)` |
| 37 |
_ = new(123) // want `call of alreadyAnnotated\(x\) can be simplified to new\(x\)` |
| 38 |
) |