Debian Codegraph @

internal/refactor/inline/testdata/multistmt-body.txtar

raw
1 Tests of reduction of calls to multi-statement bodies.
2
3 a1: reduced to a block with a parameter binding decl.
4 (Parameter x can't be substituted by z without a shadowing conflict.)
5
6 a2: reduced with parameter substitution (no shadowing).
7
8 a3: literalized, because of the return statement.
9
10 -- go.mod --
11 module testdata
12 go 1.12
13
14 -- a/a1.go --
15 package a
16
17 func _() {
18 z := 1
19 f(z, 2) //@ inline(re"f", out1)
20 }
21
22 func f(x, y int) {
23 z := 1
24 print(x + y + z)
25 }
26
27 -- out1 --
28 package a
29
30 func _() {
31 z := 1
32 {
33 var x int = z
34 z := 1
35 print(x + 2 + z)
36 } //@ inline(re"f", out1)
37 }
38
39 func f(x, y int) {
40 z := 1
41 print(x + y + z)
42 }
43
44 -- a/a2.go --
45 package a
46
47 func _() {
48 a := 1
49 f(a, 2) //@ inline(re"f", out2)
50 }
51
52 -- out2 --
53 package a
54
55 func _() {
56 a := 1
57 z := 1
58 print(a + 2 + z) //@ inline(re"f", out2)
59 }
60
61 -- a/a3.go --
62 package a
63
64 func _() {
65 a := 1
66 g(a, 2) //@ inline(re"g", out3)
67 }
68
69 func g(x, y int) int {
70 z := 1
71 return x + y + z
72 }
73
74 -- out3 --
75 package a
76
77 func _() {
78 a := 1
79 func() int { z := 1; return a + 2 + z }() //@ inline(re"g", out3)
80 }
81
82 func g(x, y int) int {
83 z := 1
84 return x + y + z
85 }