Debian Codegraph @

gopls/internal/analysis/unusedvariable/testdata/src/assign/a.go

raw symbols SCIP
1 // Copyright 2022 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package a
6
7 import (
8 "fmt"
9 "os"
10 )
11
12 type A struct {
13 b int
14 }
15
16 func singleAssignment() {
17 v := "s" // want `declared (and|but) not used`
18
19 s := []int{ // want `declared (and|but) not used`
20 1,
21 2,
22 }
23
24 a := func(s string) bool { // want `declared (and|but) not used`
25 return false
26 }
27
28 if 1 == 1 {
29 s := "v" // want `declared (and|but) not used`
30 }
31
32 panic("I should survive")
33 }
34
35 func noOtherStmtsInBlock() {
36 v := "s" // want `declared (and|but) not used`
37 }
38
39 func partOfMultiAssignment() {
40 f, err := os.Open("file") // want `declared (and|but) not used`
41 panic(err)
42 }
43
44 func sideEffects(cBool chan bool, cInt chan int) {
45 b := <-c // want `declared (and|but) not used`
46 s := fmt.Sprint("") // want `declared (and|but) not used`
47 a := A{ // want `declared (and|but) not used`
48 b: func() int {
49 return 1
50 }(),
51 }
52 c := A{<-cInt} // want `declared (and|but) not used`
53 d := fInt() + <-cInt // want `declared (and|but) not used`
54 e := fBool() && <-cBool // want `declared (and|but) not used`
55 f := map[int]int{ // want `declared (and|but) not used`
56 fInt(): <-cInt,
57 }
58 g := []int{<-cInt} // want `declared (and|but) not used`
59 h := func(s string) {} // want `declared (and|but) not used`
60
61 // (ill-typed)
62 i := func(s string) {}() // want `declared (and|but) not used`
63 }
64
65 func commentAbove() {
66 // v is a variable
67 v := "s" // want `declared (and|but) not used`
68 }
69
70 func commentBelow() {
71 v := "s" // want `declared (and|but) not used`
72 // v is a variable
73 }
74
75 func commentSpaceBelow() {
76 v := "s" // want `declared (and|but) not used`
77
78 // v is a variable
79 }
80
81 func fBool() bool {
82 return true
83 }
84
85 func fInt() int {
86 return 1
87 }