Skip to content

Commit fc70354

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/test: add test for NPE in control flow highlighting
Add a test for the fix in golang/go#65952: a nil pointer exception when highlighting a return value in a function returning no results. Also, merge tests related to control flow highlighting, since it is convenient to be able to run them together, and since there is nontrivial overhead to tiny tests. Updates golang/go#65952 Change-Id: Ibf8c7c6f0f4feed6dc7a283736bc038600a0bf04 Reviewed-on: https://go-review.googlesource.com/c/tools/+/567256 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent 77c2a67 commit fc70354

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
This test verifies document highlighting for control flow.
2+
3+
-- go.mod --
4+
module mod.com
5+
6+
go 1.18
7+
8+
-- p.go --
9+
package p
10+
11+
-- issue60589.go --
12+
package p
13+
14+
// This test verifies that control flow lighlighting correctly
15+
// accounts for multi-name result parameters.
16+
// In golang/go#60589, it did not.
17+
18+
func _() (foo int, bar, baz string) { //@ loc(func, "func"), loc(foo, "foo"), loc(fooint, "foo int"), loc(int, "int"), loc(bar, "bar"), loc(beforebaz, " baz"), loc(baz, "baz"), loc(barbazstring, "bar, baz string"), loc(beforestring, re`() string`), loc(string, "string")
19+
return 0, "1", "2" //@ loc(return, `return 0, "1", "2"`), loc(l0, "0"), loc(l1, `"1"`), loc(l2, `"2"`)
20+
}
21+
22+
// Assertions, expressed here to avoid clutter above.
23+
// Note that when the cursor is over the field type, there is some
24+
// (likely harmless) redundancy.
25+
26+
//@ highlight(func, func, return)
27+
//@ highlight(foo, foo, l0)
28+
//@ highlight(int, fooint, int, l0)
29+
//@ highlight(bar, bar, l1)
30+
//@ highlight(beforebaz)
31+
//@ highlight(baz, baz, l2)
32+
//@ highlight(beforestring, baz, l2)
33+
//@ highlight(string, barbazstring, string, l1, l2)
34+
//@ highlight(l0, foo, l0)
35+
//@ highlight(l1, bar, l1)
36+
//@ highlight(l2, baz, l2)
37+
38+
// Check that duplicate result names do not cause
39+
// inaccurate highlighting.
40+
41+
func _() (x, x int32) { //@ loc(x1, re`\((x)`), loc(x2, re`(x) int`), diag(x1, re"redeclared"), diag(x2, re"redeclared")
42+
return 1, 2 //@ loc(one, "1"), loc(two, "2")
43+
}
44+
45+
//@ highlight(one, one, x1)
46+
//@ highlight(two, two, x2)
47+
//@ highlight(x1, x1, one)
48+
//@ highlight(x2, x2, two)
49+
50+
-- issue65516.go --
51+
package p
52+
53+
// This test checks that gopls doesn't crash while highlighting
54+
// functions with no body (golang/go#65516).
55+
56+
func Foo() (int, string) //@highlight("int", "int"), highlight("func", "func")
57+
58+
-- issue65952.go --
59+
package p
60+
61+
// This test checks that gopls doesn't crash while highlighting
62+
// return values in functions with no results.
63+
64+
func _() {
65+
return 0 //@highlight("0", "0"), diag("0", re"too many return")
66+
}
67+
68+
func _() () {
69+
// TODO(golang/go#65966): fix the triplicate diagnostics here.
70+
return 0 //@highlight("0", "0"), diag("0", re"too many return"), diag("0", re"too many return"), diag("0", re"too many return")
71+
}

gopls/internal/test/marker/testdata/highlight/issue60589.txt

-30
This file was deleted.

gopls/internal/test/marker/testdata/highlight/issue65516.txt

-7
This file was deleted.

0 commit comments

Comments
 (0)