@@ -30,6 +30,14 @@ func foo(w, z *pair) *int {
30
30
}
31
31
return &a[0]
32
32
}
33
+
34
+ // address taking prevents closure inlining
35
+ func n() int {
36
+ foo := func() int { return 1 }
37
+ bar := &foo
38
+ x := (*bar)() + foo()
39
+ return x
40
+ }
33
41
`
34
42
35
43
func want (t * testing.T , out string , desired string ) {
@@ -164,12 +172,13 @@ func s15a8(x *[15]int64) [15]int64 {
164
172
// All this delicacy with uriIfy and filepath.Join is to get this test to work right on Windows.
165
173
slogged := normalize (logged , string (uriIfy (dir )), string (uriIfy ("tmpdir" )))
166
174
t .Logf ("%s" , slogged )
167
- // below shows proper inlining and nilcheck
168
- want (t , slogged , `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"nilcheck","source":"go compiler","message":"","relatedInformation":[{"location":{"uri":"file://tmpdir/file.go","range":{"start":{"line":4,"character":11},"end":{"line":4,"character":11}}},"message":"inlineLoc"}]}` )
175
+ // below shows proper nilcheck
176
+ want (t , slogged , `{"range":{"start":{"line":9,"character":13},"end":{"line":9,"character":13}},"severity":3,"code":"nilcheck","source":"go compiler","message":"",` +
177
+ `"relatedInformation":[{"location":{"uri":"file://tmpdir/file.go","range":{"start":{"line":4,"character":11},"end":{"line":4,"character":11}}},"message":"inlineLoc"}]}` )
169
178
want (t , slogged , `{"range":{"start":{"line":11,"character":6},"end":{"line":11,"character":6}},"severity":3,"code":"isInBounds","source":"go compiler","message":""}` )
170
179
want (t , slogged , `{"range":{"start":{"line":7,"character":6},"end":{"line":7,"character":6}},"severity":3,"code":"canInlineFunction","source":"go compiler","message":"cost: 35"}` )
171
- want (t , slogged , `{"range":{"start":{"line":9 ,"character":13 },"end":{"line":9 ,"character":13 }},"severity":3,"code":"inlineCall ","source":"go compiler","message":"x.bar "}` )
172
- want ( t , slogged , `{"range":{"start":{"line":8,"character":9},"end":{"line":8,"character":9}},"severity":3,"code":"inlineCall","source":"go compiler","message":"x.bar"}` )
180
+ want (t , slogged , `{"range":{"start":{"line":21 ,"character":21 },"end":{"line":21 ,"character":21 }},"severity":3,"code":"cannotInlineCall ","source":"go compiler","message":"foo cannot be inlined (escaping closure variable) "}` )
181
+
173
182
})
174
183
}
175
184
0 commit comments