Debian Codegraph @

internal/refactor/inline/testdata/newexpr.txtar

raw
1 Regression test for https://go.dev/issue/76287:
2 ensure that inlining a function that wraps go1.26's new(expr)
3 correctly inserts a conversion as needed, just as it would for a
4 declared generic function equivalent to 'new'.
5
6 - f uses a declared _new(expr) function.
7 - g uses the built-in new(expr) function.
8
9 -- go.mod --
10 module testdata
11 go 1.26
12
13 -- common.go --
14 package p
15
16 func _new[T any](x T) *T { return &x }
17
18 -- f.go --
19 package p
20
21 func f(x int64) *int64 { return _new(x) }
22
23 var _ *int64 = f(42) //@ inline(re"f", f)
24
25 -- g.go --
26 package p
27
28 func g(x int64) *int64 { return new(x) }
29
30 var _ *int64 = g(42) //@ inline(re"g", g)
31
32 -- f --
33 package p
34
35 func f(x int64) *int64 { return _new(x) }
36
37 var _ *int64 = _new(int64(42)) //@ inline(re"f", f)
38
39 -- g --
40 package p
41
42 func g(x int64) *int64 { return new(x) }
43
44 var _ *int64 = new(int64(42)) //@ inline(re"g", g)