golang.org/x/tools/gopls@v0.15.3/internal/test/marker/testdata/completion/bad.txt (about) 1 This test exercises completion in the presence of type errors. 2 3 Note: this test was ported from the old marker tests, which did not enable 4 unimported completion. Enabling it causes matches in e.g. crypto/rand. 5 6 -- settings.json -- 7 { 8 "completeUnimported": false 9 } 10 11 -- go.mod -- 12 module bad.test 13 14 go 1.18 15 16 -- bad/bad0.go -- 17 package bad 18 19 func stuff() { //@item(stuff, "stuff", "func()", "func") 20 x := "heeeeyyyy" 21 random2(x) //@diag("x", re"cannot use x \\(variable of type string\\) as int value in argument to random2") 22 random2(1) //@complete("dom", random, random2, random3) 23 y := 3 //@diag("y", re"y.*declared (and|but) not used") 24 } 25 26 type bob struct { //@item(bob, "bob", "struct{...}", "struct") 27 x int 28 } 29 30 func _() { 31 var q int 32 _ = &bob{ 33 f: q, //@diag("f: q", re"unknown field f in struct literal") 34 } 35 } 36 37 -- bad/bad1.go -- 38 package bad 39 40 // See #36637 41 type stateFunc func() stateFunc //@item(stateFunc, "stateFunc", "func() stateFunc", "type") 42 43 var a unknown //@item(global_a, "a", "unknown", "var"),diag("unknown", re"(undeclared name|undefined): unknown") 44 45 func random() int { //@item(random, "random", "func() int", "func") 46 //@complete("", global_a, bob, random, random2, random3, stateFunc, stuff) 47 return 0 48 } 49 50 func random2(y int) int { //@item(random2, "random2", "func(y int) int", "func"),item(bad_y_param, "y", "int", "var") 51 x := 6 //@item(x, "x", "int", "var"),diag("x", re"x.*declared (and|but) not used") 52 var q blah //@item(q, "q", "blah", "var"),diag("q", re"q.*declared (and|but) not used"),diag("blah", re"(undeclared name|undefined): blah") 53 var t **blob //@item(t, "t", "**blob", "var"),diag("t", re"t.*declared (and|but) not used"),diag("blob", re"(undeclared name|undefined): blob") 54 //@complete("", q, t, x, bad_y_param, global_a, bob, random, random2, random3, stateFunc, stuff) 55 56 return y 57 } 58 59 func random3(y ...int) { //@item(random3, "random3", "func(y ...int)", "func"),item(y_variadic_param, "y", "[]int", "var") 60 //@complete("", y_variadic_param, global_a, bob, random, random2, random3, stateFunc, stuff) 61 62 var ch chan (favType1) //@item(ch, "ch", "chan (favType1)", "var"),diag("ch", re"ch.*declared (and|but) not used"),diag("favType1", re"(undeclared name|undefined): favType1") 63 var m map[keyType]int //@item(m, "m", "map[keyType]int", "var"),diag("m", re"m.*declared (and|but) not used"),diag("keyType", re"(undeclared name|undefined): keyType") 64 var arr []favType2 //@item(arr, "arr", "[]favType2", "var"),diag("arr", re"arr.*declared (and|but) not used"),diag("favType2", re"(undeclared name|undefined): favType2") 65 var fn1 func() badResult //@item(fn1, "fn1", "func() badResult", "var"),diag("fn1", re"fn1.*declared (and|but) not used"),diag("badResult", re"(undeclared name|undefined): badResult") 66 var fn2 func(badParam) //@item(fn2, "fn2", "func(badParam)", "var"),diag("fn2", re"fn2.*declared (and|but) not used"),diag("badParam", re"(undeclared name|undefined): badParam") 67 //@complete("", arr, ch, fn1, fn2, m, y_variadic_param, global_a, bob, random, random2, random3, stateFunc, stuff) 68 }