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